Answer the question
In order to leave comments, you need to log in
Why doesn't get_posts work inside a post?
Site on WordPress. I'm trying to display posts from a specific category. On the pages of archives (in headings)
the code works, but for some reason it doesn't work inside the post. Please tell me what is the problem? The code:
<?php
global $post;
$postslist = get_posts( array( 'posts_per_page' => 6, 'order'=> 'DESC', 'category' => 10, ) );
foreach ( $postslist as $post ){
setup_postdata($post);
?>
<li>
<aside>
<span class="roboto title">
<a rel="bookmark" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</span>
<small class="desc"><?php the_date(); ?></small>
</aside>
</li>
<?php
}
wp_reset_postdata();
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question