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.– Álex Acuña VieraCommented Oct 25, 2011 at 13:28
Add a comment
|
2 Answers
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();
?>
<?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