I have nearly 1500 posts in my wordpress blog. Before moving to a new design, I need to tag all these posts with one tag 'old'. How can I do this? I tried to bulk edit posts and it will always go only upto 78 posts every time I tried. I tried increasing server limits and still it won't work! How can I do this?
-
It seems that you have right idea already (bulk edit) and your issue is more of making it work in your setup. Please elaborate which server settings you have tried to adjust.– RarstJul 25, 2013 at 14:46
-
Most probably is a server setting problem. Try 1) export the database 2) create a copy of database on local environment 3) enable wpdegug and wplog 4) try the bulk edit on the copy. If it works is sure a server setting problem. In this case replace the original db with the copy and try to investigate the problem. If not works maybe debug and log can help you to understand the problem.– gmazzapJul 25, 2013 at 17:04
2 Answers
If you have the ability to use wp-cli on a bash-like shell it's a handy way to do this:
for ID in $(wp post list --post_type=post --post_status=any --field=ID); do wp post term add $ID post_tag old; done
for ID in $(…); do
starts a loop for each line of output of the internal commandwp post list --post_type=post --post_status=any --field=ID
lists all post IDs of posts. It's in fact a command line interface toWP_Query
.wp post term add $ID post_tag old
assigns the termold
of the taxonomypost_tag
to each post of the loop, identified by the loop variable$ID
. If the term does not exist, it gets created on the first time.done
marks the end of the loop
Please try this
global $post;
$args = array( 'posts_per_page' => -1);
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post);
wp_set_post_tags( the_ID(), 'old', true );
endforeach;
-
2Please add an explanation to your answer: why could that solve the problem?– fuxia ♦Jul 25, 2013 at 12:25