• Resolved basbohemia

    (@basbohemia)


    I’m using the plugin on a page that runs a loop with custom post types.
    data-max-pages is always set to 0, so when I click the load more button it keeps loading posts that are already on the page.

    Here’s what my code looks like (without the html markup):

    <?php
    $work_args  = array(
        'post_type' => 'work',
        'posts_per_page' => 8
    );
    $work_query = new WP_Query($work_args);
    ?>
    <?php if ($work_query->have_posts()): ?>
    
     <?php while ($work_query->have_posts()): $work_query->the_post(); ?>
                   
    <!-- what I want to show for each post -->
                    
    <?php endwhile; ?>
    
    <?php load_more_button(); ?>
    
    <?php endif; ?>
    <?php wp_reset_query(); ?>

    What am I doing wrong?
    Thanks.

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

    (@brianbrey)

    Thanks for downloading the plugin. Unfortunately, part of keeping the plugin simple and straightforward is that it only works on main queries (blog page, search, archive, or taxonomy pages) not custom WP_Queries that might be on the page. We currently do not have plans to implement that feature at this time.

    EDIT:

    One caveat to this is that the plugin will work for custom queries if you query the ‘paged’ query var in your template.

    
    <main id="main" class="site-main" role="main">
    <?php
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    
    $args = array(
        'post_type' => 'book',
        'posts_per_page' => 4,
        'orderby'=> 'date',
        'order' => 'DESC',
        'paged' => $paged
    );
    
    $new_query = new WP_Query( $args );
    
    if ( $new_query->have_posts() ) :
    
    	/* Start the Loop */
    	while ( $new_query->have_posts() ) : $new_query->the_post();
    
    		get_template_part( 'template-parts/post/content', 'excerpt' );
    
    	endwhile;
    else :
    
    	get_template_part( 'template-parts/post/content', 'none' );
    
    endif;
    ?>
    
    </main><!-- #main -->
    
    <?php load_more_button(); ?>
    
    <?php wp_reset_postdata(); ?>
    

    If your custom page template followed this basic format, it will work. If you try to include other custom queries in the same template, however, it will most likely fail.

    • This reply was modified 7 years, 9 months ago by Idiom.
Viewing 1 replies (of 1 total)
  • The topic ‘data-max-pages always set to 0’ is closed to new replies.