Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

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.