Is there a way to bulk tag all posts which have for instance "bottle" in their titles? Thanks!


Did a little bit of searching around this site and found some links that should help you achieve your goal

1) Search all posts that match a specific title - Found this nifty code on another thread here - A use case example of the above function here

2) Updating the "tags" for a specific post is fairly simple with this function:

  wp_set_object_terms($post_id, 'mytagname', 'post_tag', true);

3) When you put everything together, it should look something like this (this code is untested)

    add_filter( 'posts_search', '__search_by_title_only', 500, 2 );

$query = new WP_Query(
        's'         => 'title_to_search_for'

remove_filter( 'posts_search', '__search_by_title_only', 500 );

if ( $query->have_posts() ) :
    while ( $query->have_posts() ) :
     $post_id = get_the_id();
        wp_set_object_terms($post_id, 'tag_to_add', 'post_tag', true);


Good luck!

| improve this answer | |
  • Hi. Thanks for your detailed reply! The problem is that I have thousand and thousand articles so the website gave me a "504 Gateway Time-out". Is there a way to achieve my goal via SQL command in phpmyadmin ? – job78 Jul 16 '14 at 13:53
  • '504 Gateway Time-Out' means the php script ran longer than the allotted execution time. use 'set_time_limit()' to increase the execution time, and the script will run fine. you should avoid direct query calls to wp db unless you really know what you're doing. – stoopkid1 Jul 17 '14 at 0:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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