Skip to content

Instantly share code, notes, and snippets.

@Rarst
Created January 16, 2013 23:08
Show Gist options
  • Save Rarst/4551879 to your computer and use it in GitHub Desktop.
Save Rarst/4551879 to your computer and use it in GitHub Desktop.
Mark WordPress posts in query if they are in main or secondary.
<?php
add_action( 'loop_start', 'mark_posts_with_query' );
function mark_posts_with_query( $query ) {
$in_main_query = $query->is_main_query();
foreach ( $query->posts as $post ) {
$post->in_main_query = $in_main_query;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment