Is there any way to update the post_content
of all posts that contain a specific product_tag
and product attribute.
$my_post = array(
'post_content' => 'New text',
);
// Update the post into the database
wp_update_post( $my_post );
Update:
I've got the query set up to pull the posts I need, now I just need to properly wp_update_post
$args = array (
'post_type' => 'product',
'post_status' => 'publish',
'numberposts' => 10,
'product_tag' => 'mug', // CHANGE THE PRODUCT TAG
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'pa_chart-type',
'field' => 'slug',
'terms' => 'nautical' // CHANGE THE CHART TYPE
)
),
);
$posts = get_posts($args);
print_r($posts);
Is there any way to update the post_content
of all posts that contain a specific product_tag
and product attribute.
$my_post = array(
'post_content' => 'New text',
);
// Update the post into the database
wp_update_post( $my_post );
Update:
I've got the query set up to pull the posts I need, now I just need to properly wp_update_post
$args = array (
'post_type' => 'product',
'post_status' => 'publish',
'numberposts' => 10,
'product_tag' => 'mug', // CHANGE THE PRODUCT TAG
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'pa_chart-type',
'field' => 'slug',
'terms' => 'nautical' // CHANGE THE CHART TYPE
)
),
);
$posts = get_posts($args);
print_r($posts);
Share
Improve this question
edited Feb 20, 2020 at 22:47
user2059376
asked Feb 20, 2020 at 22:00
user2059376user2059376
1034 bronze badges
2
|
1 Answer
Reset to default 0You can loop through each of the $posts
and update the post_content with update_post_meta
.
<?php
foreach( $posts as $p ) {
update_post_meta( $p->ID, 'post_content', 'YOURCUSTOMEDITS' );
}
?>
edit: if you want to use wp_update_post, it'd look like this:
<?php
foreach( $posts as $p ) {
$my_post = array(
'ID' => $p->ID,
'post_content' => 'New text',
);
// Update the post into the database
wp_update_post( $my_post );
}
?>
wp_update_post
– user2059376 Commented Feb 20, 2020 at 22:49