Post limit on archive page

I had a question involving limiting the # of post on a custom post type archive page.

  • Ash
    • WordPress Hacker

    Hello Luke

    Would you please try the following code in the template page?

    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    $args = array(
     'post_type' => 'press_release',
     'order'=>'DESC',
     'posts_per_page' => 10,
     'date_query' => array(
     array(
     'after' => '-30 days',
     'column' => 'post_date',
     ),
     ),
     'paged' => $paged
    );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); 
    
     // LOOP CONTENT HERE
    
    endwhile;
    ?>
    <?php wp_pagenavi( array( 'query' => $loop ) ); ?>
    <?php
    wp_reset_query();
    wp_reset_postdata();
    ?>

    And to use the wp_pagenavi function, you will need the following plugin: https://wordpress.org/plugins/wp-pagenavi/

    Please let me know if that works for you. Have a nice day!

    Cheers,
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.