Infinity Scroll working with Custom Post Types & on other pages

Hi I have 2 problems.

Firstly I have infinite scroll (IS on Jetpack) working on the posts page here http://goo.gl/HCQwoF but would like to get it working with a new query including several custom post types.

Secondly I would like to get it working on another page other than the default posts page. I have tried several things but can’t get this to work.

Any suggestions appreciated.

I have linked the following files on pastebin

home.php – http://pastebin.com/prC6zhJA (this is the working posts page)

front-page.php – http://pastebin.com/SFXTtYUn (this is the not working ‘home ‘page)

functions.php – http://pastebin.com/PkYCxeFe (the relevant parts of functions.php for IS)

content.php – http://pastebin.com/BUthRiHy (the ‘loop’ template part of IS)

  • Adam
    • Support Gorilla

    Hey @themightyant,

    I hope you’re well today and thank you for your question!

    I’ve looked through your code and I’ve noticed this part in your front-page.php file:

    $args = array(
    'post_type' => array('post', 'events', 'galleries', 'videos'),
    //'posts_per_page' => '5',
    );

    I understand that you wanted to “switch off” the post per page limit by commenting he “post_per_page” line but instead of adding “//” in front of the line you should either remove it or change to another value. By adding “//” (commenting out) inside an array you’re efficiently breaking the array, thus causing code errors. It shouldn’t work on any proper PHP configuration.

    That being said, please fix this by either removing the entire line or removing the comment “//” and see if it works. Let me know of the result please!

    Regards,

    Adam

  • Adam
    • Support Gorilla

    Hey @themghtyant,

    I hope you’re well today!

    I’ve checked your code once again and I spot a significant difference. On you working page “home.php” doesn’t use “query_posts()” function. Your “front-page.php” does.

    I’m not sure why you are using it as it’s called with the same set of arguments as the “WP_Query()” above. That might cause some unexpected behavior. What’s even more important, is that

    Pagination won’t work correctly, unless you set the ‘paged’ query var appropriately: adding the paged parameter

    [WP Codex]

    No infinite scroll will work if the pagination doesn’t. That said, most likely this is the reason.

    Here’s an information on how to properly add pagination:

    https://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query

    Give it a try please and let me know if it helped!

    Cheers,

    Adam

  • Adam
    • Support Gorilla

    Hey themightyant,

    I hope you’re well today!

    I’ve accessed your dashboard and took a look at the settings and configuration. It seems like there’s nothing wrong with it but I think the glitch here may be a custom loop.

    You’re using an altered loop code to display posts on your front side. According to the Jetpack’s Infinite Scroll documentation, such a custom loop should be explicitly specified in IS config. That said, please try moving/copying the entire “loop part” from your template file to the functions.php file and wrap it up in a function like this:

    function my_custom_post_wall() {

    /... here goes your custom loop code,
    you may need to declare global variables right before it, like:
    global $paged;
    .../
    }

    Having this in your functions.php you may first test it with a template, simply by calling the function within a template file. When it works, change your IS config to:

    add_theme_support( 'infinite-scroll', array(
    'container' => 'wall-posts',
    'footer' => 'footer',
    'type' => 'scroll',
    'wrapper' => false,
    'posts_per_page' => 11,
    'render' => 'my_custom_post_wall'
    ) );

    Let me know if it worked and if you have any further questions, I’ll be glad to assist!

    Cheers,

    Adam