OK, so a little bit of guessing is involved in that answer, since you’ve posted only parts of your code, but… I assume that your code looks like that:
$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 );
}
If so, then the problem lies in this line:
'post_category' => array(14,16,19);
There is no post_category
argument for WP_Query…
The correct argument is category__in
, so your code should look like this:
$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 );
}
PS. Since you only use IDs, there is no point in getting whole posts. It would be much more efficient if you used fields => 'ids'
in your query.