V
V
Valery232020-04-25 21:36:20
WordPress
Valery23, 2020-04-25 21:36:20

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

1 answer(s)
G
grkvnko, 2020-04-26
@grkvnko

Try removing global $post; and change $post

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question