The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Why is archive.php displays all post, not only month (4 posts)

  1. jonas18z
    Posted 3 years ago #

    I have a archive page that I display with:

    <?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>

    But when press on a link it's shows all post in 'may' for example, it show all post from every month:

    Here is get post from my archive.php

    $args = array( 'numberposts' => 99 );
    $lastposts = get_posts( $args );
    foreach($lastposts as $post) : setup_postdata($post); ?>
    <!-- Start post -->
                				<div class="top_news">	
                    <img src="<?php echo get_post_meta($post->ID, 'news_first_image', true); ?>"/>
    				<?php } ?>
    				<h2><?php the_title(); ?></h2>
    					<?php the_content(); ?>
    			<!-- End Post -->
    <?php endforeach; ?>   

    Anyone know what the problem is?

  2. jonas18z
    Posted 3 years ago #

    Sorry for bump, but I still have this problem. What do I missing?

  3. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    Try getting rid of the custom query (i.e. get_posts() ) and just use the normal loop:

    if ( have_posts() ) : while ( have_posts() ) : the_post();
        // Loop markup here
    endwhile; endif;

    The problem is your custom loop is stomping the normal query that WordPress is attempting to use, and it is that normal query that knows to display only posts from the given month.

    You're telling WordPress, "Don't use the query you want to use; use my custom query instead."

  4. jonas18z
    Posted 3 years ago #

    Works!! thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic