Support » Themes and Templates » Archive Loop displaying everything

  • Hey everyone,

    Having some trouble with my Archive loop in my custom theme. It’s been working fine, but I’ve just noticed that instead of being context specific (displaying posts from a certain category, by a certain author etc.) it’s now just showing everything that’s ever been posted on the site.

    I’ve been trying to find the problem for hours now, but I’m completely stumped.

    Here’s the code:

    if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } else if ( get_query_var('page') ) {$paged = get_query_var('page'); } else {$paged = 1; }
    $archiveArgs = array( 'posts_per_page' => 8, 'paged' => $paged, 'post_type' => array('post','review') );
    $archiveLoop = new WP_Query();
    $archiveLoop->query( $archiveArgs );
    while ( $archiveLoop->have_posts() ) : $archiveLoop->the_post(); ?>

    Any ideas?

    Thanks for taking the time have a look!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Michael


    Forum Moderator

    there is nothing in your custom query to tell the loop to only show posts of a particular archive;

    possibly have a look at:

    what theme are you working with, and where did you download it from?

    Thanks for replying!

    I’m developing using the Underscores theme by Automattic –

    I’ve changed the original code to support my additional post type.

    This was the original archive loop –

    <?php /* Start the Loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>

    Could it simply be because I’m resetting the WordPress Query before the loop is being run?



    Forum Moderator

    possibly just try to change the original code to:

    <?php /* Start the Loop */ ?>
    <?php global $wp_query;
    $args = array_merge( $wp_query->query_vars, array( array('post','review') );
    query_posts( $args ); ?>
    <?php while ( have_posts() ) : the_post(); ?>


    or alternatively try and use ‘pre_get_posts’ action in functions.php of your theme:

    //add custom post type to archives//
    add_filter('pre_get_posts', 'add_archive_query_post_type');
    function add_archive_query_post_type($query) {
      if( is_archive() ) {
        $post_type = get_query_var('post_type');
    	    $post_type = $post_type;
    	    $post_type = array('post','review');
    	return $query;


    First solution worked perfectly, thankyou very much!

    Thanks for also linking me to the pre_get_posts function. Looks interesting!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Archive Loop displaying everything’ is closed to new replies.