Support

Account

Home Forums ACF PRO Use a Select Field to limit number of posts displayed

Helping

Use a Select Field to limit number of posts displayed

  • Hi there! I am revamping a site and one section will show the excerpts from x number of the most recent custom posts. My client would like to be able to change how many posts display there on the fly (so one month it might display the most recent 3, another it might display 6), so was hoping to use an ACF select field or just a text field to allow him to set that.

    Normally I would have some code similar to this:

    <?php
      query_posts( array( 'post_type' => 'Games', 'showposts' => 5 ) );
      if ( have_posts() ) : while ( have_posts() ) : the_post();
    ?>
    
    <div class="onepost">
    		<div class="thumbnail"><a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a></div>
    		<div class="blogtitle"><h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
    		</div>
    <?php endwhile; ?><?php endif; ?>

    How can I use ACF to change the “showposts” variable?

  • Create an options page and put a field on it to use and then do something like this

    
    query_posts( array( 'post_type' => 'Games', 'showposts' => get_field('your-field-name', 'options') ) );
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Use a Select Field to limit number of posts displayed’ is closed to new replies.