0

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

http://www.problogdesign.com/wordpress/load-next-wordpress-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?

Thanks

3 Answers 3

1

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

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 :)

0

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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