WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I found an amazing plugin that loads the next posts with Ajax.


However it doesn't work with custom post types.

The code looks fairly simple. Any idea how to edit the code to use custom post types?


share|improve this question
up vote 1 down vote accepted

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
share|improve this answer
Thanks very much. I'll give this a go and let you know how I get on – fxfuture Jan 16 '12 at 22:58
It still isn't clear on what to change to make this plugin work – Terrell Anderson Aug 21 '12 at 23:32

I don´t know if someone is still looking to resolve this, but this is how I did it:

In the "load-posts.js" you have this line:

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

This looks for the class ".post" to load more. The custom post types doesn´t have this class. So simply change this line for something like:

$('.pbd-alp-placeholder-'+ pageNum).load(nextLink + ' .status-publish',

And it will work everywhere. I hopes this helps someone, I was fighting with this problem almost a week until I found the solution :)

share|improve this answer

Found this in the comments:

The following will point you in the right direction: add your custom post-type to $wp_query by adding the following:

$args = array(
    'post_type' => 'post-type'

And: $query = new WP_Query($args); above $max = $wp_query->max_num_pages;

From there on you can pretty much customize it the way you like - even integrate your theme options if you have them!

(I renamed $wp_query to $query by the way, not sure if that is really necessary)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.