0
votes

I am new to wordpress. I am trying to show posts from a specific category to my homepage. The category has more than one post but when using the wp_query method, only one post in getting showed even when I'm using the posts_per_page.

<?php
    $args = array(
        'cat' => '3',
        'posts_per_page' => '10'
    );
    $upcoming =  new WP_Query($args); 
    while($upcoming->have_posts()){
    $upcoming->the_post();                  
    } 
?>

        <div class="card border-1">

    <div class="card-body">
    <h6><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h6>
    <p class="text-muted card-text"><?php the_excerpt(); ?></p>

<?php 
    wp_reset_postdata(); 
?>
1

1 Answers

0
votes

You need to move your output inside the loop:

<?php
$args = array(
    'cat' => '3',
    'posts_per_page' => '10'
);
$upcoming =  new WP_Query($args); 
while($upcoming->have_posts()){
  $upcoming->the_post();                  
?>
  <div class="card-body">
  <h6><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h6>
  <p class="text-muted card-text"><?php the_excerpt(); ?></p>  
<?php
} 

  wp_reset_postdata(); 
?>