WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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'm doing something wrong here.

I'm trying to add a custom post type, external-videos, to the main blog query in all instances. It's working in the main blog page for the first load of posts but the custom post type is ignored in subsequent posts loaded by infinite scroll. Only "regular" posts are loaded thereafter.

I'm using the wp plugin version of infinite scroll. Here's my function:

// add external-videos to the loop

function add_external_videos_to_query( $query ) {

    if ( is_main_query() && is_home() )
        set_query_var ( 'post_type', array('post','external-videos') );
add_action( 'pre_get_posts', 'add_external_videos_to_query' );

Also, seemingly related - the custom post_type is being ignored by infinite scroll even on the archive page for that custom post type. In other words, on the archive page for "external videos," the first page of "external videos" posts loads, but no further posts of that type load via infinite scroll.

Infinite scroll is working correctly for all other archives I've tested.

Incidentally I've read Mike Schinkel's reply here and I think i'm using a similar technique, but I'm not sure if i need global $wp_the_query or not.

For another situation, but also trying to get pre_get_posts to fire every query, he said:

Basically what you are looking for is the global $wp_the_query variable which is set to the value of the main query. It may not be a perfect fit for 100% of cases but will probably work fine in 99% of cases:

add_action( 'pre_get_posts', 'custom_post_count' );
function custom_post_count( $query ){
  global $wp_the_query;
  if ( $wp_the_query === $query ) {
    $query->set( 'posts_per_page', 5 );
  return $query;
share|improve this question
is_main_query was added in WP3.3 as a shortcut for checking $wp_the_query === $query, it's doing the same thing behind the scenes. – Milo Sep 5 '12 at 17:51
Thanks. yes, that's what i inferred from Mike's comment below his post. I must be missing something else, or else infinite scroll somehow skips pre_get_posts? – nimmolo Sep 5 '12 at 19:14
I'm beginning to think this may be an issue with the way the infinite scroll plugin accesses wp_query. – nimmolo Sep 7 '12 at 3:26

@nimmolo since we solved this, we should leave for posterity that the solution had nothing to do with pre_get_posts. We needed to check the post class selectors for the video posts were the same as for regular posts.

share|improve this answer
Yes - sorry. This question is resolved, I had the post class selectors specified incorrectly for the custom post type. – nimmolo Sep 16 '12 at 20:01

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.