WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have added a custom taxonomy to my posts, that will get a value by iteself on post_update action. What will be the SQL query to update all my posts at once so that the taxonomy value is added to each of them. Also will updating from SQL call the update_post action of wordpress?

share|improve this question

I got the same need, personally I used wp_set_object_terms after a WP_Query resquest on all of my custom post type. I suppose you could replace my_custom_type with post in the following quote of my code:

$my_query = array(
    'post_type' => array( 'post', 'my_custom_type' ) );
$the_query = new WP_Query( $my_query );

while ( $the_query->have_posts() ) : $the_query->the_post();

    $id = get_the_ID();
    wp_set_object_terms( $id, "my_new_tag_value", "my_tax_slug", $append=true );

share|improve this answer

I would not do this with SQL. I would do this with WP_Query. You can use WP_Query to get all desired posts...which in this case is all posts. Then you can loop through the posts and use wp_set_object_terms() to set the desired category (or categories) on each post.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.