好的,这个答案中有一点猜测,因为您只发布了部分代码,但是。。。我假设您的代码如下所示:
$args = array(
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'posts_per_page\' => -1,
\'post_category\' => array(14,16,19)
);
$posts = get_posts($args);
foreach ( $posts as $post ) {
$dealcode = "&deal_code=coupon";
$urlvalue = get_post_meta( $post->ID, \'metakey\', false);
$urlvalue = $urlvalue . $dealcode;
update_post_meta( $post->ID, \'metakey\', $urlvalue );
}
如果是,那么问题就在于这一行:
\'post_category\' => array(14,16,19);
没有
post_category
argument for WP_Query...
正确的参数是category__in
, 因此,您的代码应该如下所示:
$args = array(
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'posts_per_page\' => -1,
\'category__in\' => array(14,16,19)
);
$posts = get_posts($args);
foreach ( $posts as $post ) {
$dealcode = "&deal_code=coupon";
$urlvalue = get_post_meta( $post->ID, \'metakey\', false);
$urlvalue = $urlvalue . $dealcode;
update_post_meta( $post->ID, \'metakey\', $urlvalue );
}
另外,由于您只使用ID,所以获取完整的帖子是没有意义的。如果您使用
fields => \'ids\'
在您的查询中。