WordPress.org

Ready to get started?Download WordPress

Forums

numberposts is not working for me (2 posts)

  1. phpchick
    Member
    Posted 3 months ago #

    <?php
    // args
    $args = array(
    	'numberposts' => 3,
    	'post_type' => 'earnings',
    	'meta_key' => 'article_category',
    	'meta_value' => 'Immediately Actionable'
    );
    // get results
    $the_query = new WP_Query( $args );
    // The Loop
    ?>
    <?php if( $the_query->have_posts() ): ?>
    	<ul class="frontnewsul">
    	<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    		<li class="frontnewsli">
    			<a href="<?php the_permalink(); ?>"><div class="stksymnewshdln"><?php the_field('symbol'); ?></div><span class="frontnewslink"><?php the_title(); ?></span></a>
    		</li>
    	<?php endwhile; ?>
    	</ul>
    <?php endif; ?>
    <?php wp_reset_query();  // Restore global post data stomped by the_post(). ?>

    The number of posts that is shown is ALL of them, rather than the 3 that I would like. Can anybody help out on this? I have this snippet of code on the front page. There are other loops going on in the front-page, not sure if that has anything to do with it.

  2. Dave Naylor
    Member
    Posted 3 months ago #

    Use posts_per_page

Reply

You must log in to post.

About this Topic