• Hi,

    I want to load more posts on button click but it only load 2 posts and no more. Please help.

    <?php

    if (isset($_POST[‘button’])) :
    $ids=array();
    query_posts(array(‘posts_per_page=2’),array(‘posts__not_in=$ids’));

    //query_posts(array(‘post__not_in’ => $ids));
    while ( have_posts() ): the_post();

    /*
    * Include the Post-Format-specific template for the content.
    * If you want to override this in a child theme, then include a file
    * called content-___.php (where ___ is the Post Format name) and that will be used instead.*/

    $ids[] = get_the_ID();
    get_template_part( ‘content’);
    // End the loop.
    endwhile;
    wp_reset_query();
    endif; ?>

    <?php endif; ?>

Viewing 1 replies (of 1 total)
  • Hi,

    load more posts button loads only 2 posts because you have passed following argument:

    (array(‘posts_per_page=2’)

    You’ll have to replace 2 with the number of posts you want to display. In other case, you do not pass this argument, button will show all posts.

    Thanks,

Viewing 1 replies (of 1 total)
  • The topic ‘Load more posts on button click’ is closed to new replies.