Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Idiom

    (@brianbrey)

    Thanks for downloading the plugin.

    The button should remove itself once there are no more posts to display. If you view source or ‘Inspect Element’ on the button, do you see something like data-page="1" data-max-pages="3"? The way it works is that the data-page attribute is updated every time you click the button, and if the data-page number equals the data-max-pages number it deletes itself. Could you double check that the data-page and data-max-pages attributes are showing and updating correctly?

    Sounds similar to my issue. I’m using a custom post type which the PHP code in the page template states to display 9 posts per page (I can change that to any number of posts per page; see code below). Could that have anything to do with what’s causing this issue, a custom post type?

    <?php
    query_posts(array(
        'post_type' => 'blog_post',
        'posts_per_page' => 9,
        'orderby'=> 'date',
        'order' => 'DESC',
        'paged' => $paged
    ));
    ?>

    The data-page is “1” and the data-max-pages is “0” in the code of my page when I inspect it.

    • This reply was modified 7 years, 8 months ago by Adam.
    • This reply was modified 7 years, 8 months ago by Adam.
    • This reply was modified 7 years, 8 months ago by Adam.
    • This reply was modified 7 years, 8 months ago by Adam.
    Plugin Author Idiom

    (@brianbrey)

    Hi Adam. I thought it might be an issue with using query_posts() to change the query or maybe something with custom post types. I’ve tested both those scenarios on a clean WordPress install with minor customization to twentyseventeen theme, and I was unable to replicate your problem.

    Is there anything in your template that is manipulating the main query before you call the load_more_button() function? Maybe is there a wp_reset_postdata()? If that’s the case, inserting the load more button before the main query is reset should solve this issue.

    @brianbrey – You’re so right! I had a similar function at the end wp_reset_query(). I placed that after the load_more_button() and the button disappeared after the last posts were loaded. Thank you so much!

    Plugin Author Idiom

    (@brianbrey)

    Great to hear! Glad that was the solution.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Hide load more button when there are no more posts’ is closed to new replies.