[resolved] Custom infinite scroll and archives/search (4 posts)

  1. Adam
    Posted 2 years ago #

    I have a file (loop.php) which contains the loop (while (have_posts ... endwhile)
    Next I have an index.php, archive.php and a search.php. All of which contain get_template_part('loop').

    In my functions.php I add a hook called wp_ajax_infinitescroll which executes the following function:

    function MyInfiniteScroll(){
       $loop        = $_POST['loop'];
       $page           = $_POST['page'];
       query_posts(array('paged' => $page ));

    Then I have some JavaScript which does (I left out some code here to simplify):

        url: "http://xxxxxxxxx/wp-admin/admin-ajax.php",
        data: "action=infinitescroll&page="+ pagenr + '&loop=loop',
        success: function(html){

    My problem: on index.php this works perfectly, it shows all posts.
    On both archive.php and search.php the first "page" works also, but any subsequent "pages" load all the posts again and not those limited to the search or archive.
    I suppose somewhere along the line WP_Query is "reset"? So what am I doing wrong here/am I forgetting?

    PS: before someone tells me there is an infinite-scroll plugin, I know. However it is not usable in this particular case which is why I try to write my own.

  2. Adam
    Posted 2 years ago #

    I came to the conclusion I oversimplified my idea so I am completely rewriting this code from a different angle. Sorry for the void question, please ignore this thread.

  3. John Wilson
    Posted 2 years ago #

    Hi Umbercode, did you ever find a solution to this?

    I have infinite scroll working on the search page, but loading page 2 just loads the default loop not those limited to the search.

  4. Adam
    Posted 2 years ago #

    Hi John,

    Yes, I did manage to get it working...sort of.
    I spent too much time on the problem and in the end I got something that did what it had to do, but not without bugs. For the client it was good enough and I ran out of budget, so I left it at that.
    It has been a while and the project is archived, but I remember using this article as a startingpoint: http://wp.tutsplus.com/tutorials/theme-development/how-to-create-infinite-scroll-pagination/ (remember to also read the comments).
    Try it, if you still cannot get it to work I could go and find the code in my project.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.