當我嘗試在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'作爲帖子標題的帖子。因爲它返回具有不同標題的帖子。馬上。 –