有没有办法更新post_content
包含特定product_tag
和产品属性。
$my_post = array(
\'post_content\' => \'New text\',
);
// Update the post into the database
wp_update_post( $my_post );
Update:我已经设置好了查询以获取我需要的帖子,现在我只需要正确地
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);
最合适的回答,由SO网友:Robert DeVore 整理而成
您可以循环通过$posts
并使用更新post\\u内容update_post_meta
.
<?php
foreach( $posts as $p ) {
update_post_meta( $p->ID, \'post_content\', \'YOURCUSTOMEDITS\' );
}
?>
编辑:如果要使用wp\\u update\\u post,则如下所示:
<?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 );
}
?>