Load Next WordPress Posts With AJAX?

In principal, you could use this with any archive page. All it’s doing is fetching the next page of results and displaying the data.

The reason it won’t work with CPTs is because of the way the PHP script is queued – with an !is_singular() filter.

The core of the plugin is in the JavaScript. Namely, this section:

$('.pbd-alp-placeholder-' + pageNum).load(nextLink + ' .post',
    function() {

You are loading into a placeholder element the HTML contents of the “next posts” page. jQuery will fetch the page, select just the part that has a class of “post” (the + ' .post' part).

You aren’t doing any custom queries or lookups, just using a link WordPress generates for you by default (next_posts() creates a link to the next page of results).

So to make this work with CPTs you’ll need to do two things:

  1. Make sure the script is triggered for your custom post type archive page.
  2. Make sure your CPT supports archives and pagination