• Hello, I’m trying to use this plugin with get_posts but it is not working.
    The code I’m using:

    $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
    			$args = array('post_type'=> 'custom_post','posts_per_page' => 5, 'paged' => $paged,);
    			$myposts = get_posts( $args );
    			foreach( $myposts as $post ) : setup_postdata($post);
    //content
    echo easy_wp_pagenavigation( $myposts );

    Can you please tell what’s wrong?

    It is working fine if I use

    $myposts = new WP_Query( $args );
    while ( $myposts->have_posts() ) : $myposts->the_post();

    https://www.ads-software.com/plugins/easy-wp-page-navigation/

Viewing 1 replies (of 1 total)
  • Plugin Author PenciDesign

    (@bboy8k)

    Hello,

    Why you not use WP_Query() ? With this code, you can do that like so:

    $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
    $args = array('post_type'=> 'custom_post','posts_per_page' => 5, 'paged' => $paged,);
    $myposts = new WP_Query( $args );
    if( $myposts->have_post() ):
    while ( $myposts->have_posts() ) : $myposts->the_post();
    //content
    endwhile; wp_reset_postdata();
    echo easy_wp_pagenavigation( $myposts );
    endif;

    The sweet and short of this, don’t use get_posts if you need paginated queries. get_posts works perfectly if you are going to use a custom query that doesn’t need pagination, but it really becomes a big complicated mess when you need to introduce pagination.

    Best regard,
    Pham Tuan

Viewing 1 replies (of 1 total)
  • The topic ‘pagination with get_posts’ is closed to new replies.