当我尝试在wordpress中使用get_post时,它总是返回最后一个帖子。get_post通过帖子标题总是返回最后插入的帖子
$the_code = 'couponcode';
$args = array(
'post_title' => 'couponcode',
'post_type' => 'shop_coupon',
'post_status' => 'publish',
'numberposts' => 1
);
$my_code = get_posts($args);
我这是怎么插入的优惠券后:
$coupon = array(
'post_title' => 'couponcode',
'post_content' => '',
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'shop_coupon'
);
$new_coupon_id = wp_insert_post($coupon);
好吗显示了在后端管理。
是啊,这是正确的。它应该返回给你什么? – Lutrov
您正在查询以获取最后插入的一个。如果您需要更多数据,请更改“numberposts”值 –
如何仅返回具有'couponcode'作为帖子标题的帖子。因为它返回具有不同标题的帖子。马上。 –