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


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:

      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>
    <?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)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.