Skip to content

Instantly share code, notes, and snippets.

@LeanSeverino1022
Last active April 5, 2020 13:00
Show Gist options
  • Select an option

  • Save LeanSeverino1022/c979e374cf53807a16bf6a349f985a3b to your computer and use it in GitHub Desktop.

Select an option

Save LeanSeverino1022/c979e374cf53807a16bf6a349f985a3b to your computer and use it in GitHub Desktop.
[Custom Query Pagination] #wordpress

Example

The simple yet important lines are

'paged' => get_query_var('paged', 1), //1 is fallback if wp cannot find the page number dynamically
AND

'total' => $pastEvents->max_num_pages,

$max_num_pages // The total number of pages. Is the result of $found_posts / $posts_per_page. https://developer.wordpress.org/reference/classes/wp_query/#properties

       
        $evts = new WP_Query(array(
            'paged' => get_query_var('paged', 1), //1 is fallback if wp cannot find the page number dynamically
            'posts_per_page' => 1, //show 1 post per page
            'post_type' => 'event',

        ));

        while($evts->have_posts()) {
            $evts->the_post(); ?>

            <p> <?php the_title() ?> </p>
             <p> <?php the_content(); ?> </p>

       <?php }
        echo paginate_links(array(
            'total' => $evts->max_num_pages,
        ));
       ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment