I need to replace all post_content in a particular tag/category to the desired one i have. is their a plugin to accomplish it or is their a query to finish this. Iam sick of doing this manually, is their a way to accomplish it.

  • Maybe if you explain what is the post_content's content... Is always the same? It's a string/text that you want to modify with regex or something? If is that so, you could do a query with the tag/category in scope, and wp_update_post() would do the magic. Oct 25 '11 at 13:28

This is what I mean:

$tochange = get_posts('numberposts=-1&post_type=any&category_name=category-name-you-want-to-change');
foreach($tochange as $post){
        $contentchange = ''; /*here you do the magic, string replace or whathever you want to do*/
        $tochange = array();
        $tochange['ID'] = $post->ID;
        $tochange['post_content'] = $contentchange;
        $out = wp_update_post($tochange);
function update_post_do()
global $wpdb;
$wpdb->query("UPDATE wp_posts p
INNER JOIN wp_term_relationships AS tr ON (p.ID = tr.object_id)
INNER JOIN wp_term_taxonomy AS tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id
AND tt.taxonomy = 'your_category' AND tt.term_id
IN ( 1 )) SET p.post_content = 'your content'");

Mention the category, id and the content to update

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.