Php 如何阻止被排除在外的类别显示其粘性帖子?
我有一个包含排除类别(特色)的循环,因此现在我的类别在循环中不可见Php 如何阻止被排除在外的类别显示其粘性帖子?,php,wordpress,Php,Wordpress,我有一个包含排除类别(特色)的循环,因此现在我的类别在循环中不可见现在我的问题是,如果我将我在特色类别中的帖子设置为“粘性”,那么帖子仍然会显示在我的循环中我想做的是隐藏该类别的粘性帖子(特色),但允许我的其他帖子(来自其他类别)是“粘性”的。 我的循环: <?php $category = get_cat_ID('Featured');//Get our Featured Category $args = array( 'cate
现在我的问题是,如果我将我在特色类别中的帖子设置为“粘性”,那么帖子仍然会显示在我的循环中
我想做的是隐藏该类别的粘性帖子(特色),但允许我的其他帖子(来自其他类别)是“粘性”的。
我的循环:
<?php
$category = get_cat_ID('Featured');//Get our Featured Category
$args = array(
'category__not_in' => $category //Category is excluded
// but 'sticky' ones from Featured category
// are still showing up...
);
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query($args);
if($wp_query->have_posts()):?><?php while ( $wp_query->have_posts() ) : $wp_query->the_post();?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<div class="entry">
<?php the_content(__('Read more','my-domain')); ?>
</div><!--/entry-->
</div><!--/post_class-->
<?php endwhile; ?>
<?php endif; ?><!--END if THE LOOP-->
<?php
$wp_query = null;
$wp_query = $temp;
wp_reset_query();
?>
有什么想法可以解决这个问题吗?我没有可用的测试系统,但是根据,类似这样的系统应该可以工作:
$sticky = get_option( 'sticky_posts' );
$args = array(
'category__not_in' => $category,
'ignore_sticky_posts' => 1,
'post__not_in' => $sticky
);
$query = new WP_Query( $args );
谢谢你的回答,但它并没有像预期的那样工作,因为现在它隐藏了我所有的贴子,包括其他类别的贴子…该死,对不起。在一个查询中看不到明显的方法。你能做一个查询来获取你类别中所有的粘性帖子,然后只使用
post\uuuu not\uu in
子句中的那些帖子吗?我假设ignore\u sticky\u posts
参数本身不起作用。或者,您可以在循环中使用in\u category()
,必要时执行continue
。但我的直觉是效率会降低——我想这意味着更多的数据库调用;很高兴为您提供帮助在我从您的代码中删除“post\u not\u in”=>$sticky之后,我似乎正在按预期工作。