Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  Álex Acuña Viera Oct 25 '11 at 13:28

2 Answers 2

This is what I mean:

<?php 
$tochange = get_posts('numberposts=-1&post_type=any&category_name=category-name-you-want-to-change');
foreach($tochange as $post){
    setup_postdata($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);
        unset($tochange);
    }
wp_reset_query();
?>
share|improve this answer
<?php 
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'");
}
add_action('init','update_post_do'); 
?>

Mention the category, id and the content to update

share|improve this answer

Your Answer

 
discard

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.