Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

This get_posts function displays all the articles of the categories except one.

numberposts => -1 is specified to retrieve all the articles in a category.

why am I not showing them all?

Thx!


<?php $related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => -1, 'post__not_in' => array($post->ID) ) );
if( $related ) foreach( $related as $post ) 
{ setup_postdata($post); ?>
            <div class="article">        
                <a class="article_link" href="<?php the_permalink(); ?>" title="En savoir plus"><?php the_title(); ?></a>
            </div>
        <?php 
} wp_reset_postdata(); ?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
352 views
Welcome To Ask or Share your Answers For Others

1 Answer

Because in your get_posts() function, you are passing the parameter:

'post__not_in' => array($post->ID)

So the get_posts() would retrieve all posts, except the current one (which you are passing via $post->ID)

Here's the screenshot of the documentation:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...