简体   繁体   English

使用sticky_post从wp查询计数帖子

[英]counting post from a wp-query using sticky_post

I'm trying to count the number of sticky_posts inside a specific category. 我正在尝试计算特定类别内的sticky_posts的数量。

first I get all the sticky posts : 首先,我得到了所有粘性帖子:

$sticky = get_option( 'sticky_posts' );

then here are my args : 然后这是我的参数:

$args_sticky = array(
'post_type' => 'post',
'post__in'  => $sticky,
'post__not_in'  => array($post->ID),
'category__in' => wp_get_post_categories($post->ID),
);

and then I try to count the number of posts from those args : 然后我尝试计算这些args的帖子数量:

$sticky_number = count($args_sticky); 

the problem is that I get not the right result. 问题是我没有得到正确的结果。 I don't know what I'm doing wrong... 我不知道我在做什么错...

here is my full php code : 这是我完整的php代码:

<?php 
$sticky = get_option( 'sticky_posts' );
$args_sticky = array(
'post_type' => 'post',
'post__in'  => $sticky,
'post__not_in'  => array($post->ID),
'category__in' => wp_get_post_categories($post->ID),
);


$sticky_number = count($args_sticky); 

echo $sticky_number;
    ?>

can anybody help me with this ? 有人可以帮我吗?

thanks a lot for your help, 非常感谢你的帮助,

You are not counting the right thing. 您没有在计算正确的事情。 It should be: 它应该是:

$sticky_number = count($sticky);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM