Support

Account

Home Forums ACF PRO Pagination – how to add numbered pagination

Helping

Pagination – how to add numbered pagination

  • I would like to add numbered pagination to my blog landing page. Typical pagonation codes from WOrdpress do not work in my query – I am using custom field as an event date, and I order posts by that custom field. Can anyone help me set up pagination in my query please:

    <?
        /*
        *  Order Posts based on Date Picker value
        *  this example expects the value to be saved in the format: yymmdd (JS) = Ymd (PHP)
        */
    
        $args = array(
            'posts_per_page'=>12,
            'meta_key' => 'event_date', // name of custom field
            'orderby' => 'meta_value_num',
            'order' => 'DSC',
            'cat' => '2'
        );
    
        $the_query = new WP_Query( $args );
    
             if ( $the_query->have_posts() ) {
                while ( $the_query->have_posts() ) { 
        ?>			
                <?php $the_query->the_post(); ?>
    
                                <?php 
                                    $date = get_field('event_date');
                                    $dateformat = date("F j, Y", strtotime($date));
                                ?>
                                <p class="date"><?php echo $dateformat; ?> 
    
                                <?php the_title(); ?>
                                <?php the_post_thumbnail( 'thumb-270x270' ); ?></a>
                                <?php the_tags( '', ', ', ''); ?>
    
            <?php } } else { ?>
                <h2>Not Found</h2>
            <?php } ?>
            </ul>
            
            
            <?php wp_reset_postdata(); ?> 
  • Since this is the blog landing page, I’m assuming that it’s index.php or something similar, have you tried using the WP hook pre_get_posts to modify the main query rather doing a new query? https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.