[英]WP_query, meta_query NOT LIKE doesn't work
我的meta_query不起作用,我也不明白為什么。 我在變量中有帖子狀態(存檔),沒有此帖子狀態就不會顯示帖子。
function getNewsListings($numberOfListings, $status) {
$args = array(
'post_type' => 'news',
'posts_per_page' => $numberOfListings,
'meta_query' => array(
'key' => 'post_status',
'value' => $status,
'compare' => 'NOT LIKE'
)
);
$listings = new WP_Query($args);
if ($listings->found_posts > 0 ) {
echo '<ul id="news_list" style="list-style-type:none">';
while ($listings->have_posts()) {
$listings->the_post();
$listItem = '<li id="news"><a href="' . get_permalink() . '">';
$listItem .= get_the_title() .'</a><hr></li>';
echo $listItem;
}
echo '</ul>';
wp_reset_postdata();
} else {
echo '<p>No news found</p>';
}
}
嘗試下面的代碼來顯示具有post_type 新聞的帖子。
function getNewsListings($numberOfListings, $status) {
$args = array(
'post_type' => 'news',
'posts_per_page' => $numberOfListings,
'post_status' => $status
);
$listings = new WP_Query($args);
if ($listings->found_posts > 0 ) {
echo '<ul id="news_list" style="list-style-type:none">';
while ($listings->have_posts()) {
$listings->the_post();
$listItem = '<li id="news"><a href="' . get_permalink() . '">';
$listItem .= get_the_title() .'</a><hr></li>';
echo $listItem;
}
echo '</ul>';
wp_reset_postdata();
} else {
echo '<p>No news found</p>';
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.