![](/img/trans.png)
[英]How can I use WP_Query to display selected Category posts from the custom post?
[英]WP display posts without custom post status
我需要显示没有自定义帖子状态(存档或精选)的帖子。 但是,当我写post_status!= .$status
它不起作用,并显示所有帖子。
对不起,我的英语不好。 但我需要帮助
function getNewsListings($numberOfListings, $status) {
$listings = new WP_Query();
$listings->query('post_type=news&post_status!=' . $status . '&posts_per_page=' . $numberOfListings );
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_status' => 'publish'
(因为如果您知道不需要的帖子状态,则应该知道想要的内容,并且您将始终使用此名称):
$query = new WP_Query( array( 'post_status' => 'publish' ) );
更多信息:
https://codex.wordpress.org/Class_Reference/WP_Query#Status_Parameters
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.