Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#21522 closed defect (bug) (invalid)

Custom posts query does not work on index with paged var

Reported by: adrian7's profile adrian7 Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4
Component: Query Keywords: close
Focuses: Cc:

Change History (5)

#1 @SergeyBiryukov
12 years ago

  • Description modified (diff)

#2 @ocean90
12 years ago

  • Keywords close added; 2nd-opinion dev-feedback removed
  • Severity changed from major to normal

The problem is the use of query_posts() here. You should hook into the pre_get_posts, since query_posts() is too late.

#3 @adrian7
12 years ago

  • Resolution set to fixed
  • Status changed from new to closed

Thanks @ocean90 it worked like a charm. Here's the code I used:

function nm_index_query( $query ){

	$paged = intval( get_query_var('paged') );

	if ( $query->is_home() && $query->is_main_query() ) {
		$query->set( 'post_type',  array('post', 'movie', 'director', 'actor'));
		$query->set( 'paged',  $paged);

add_action( 'pre_get_posts', 'nm_index_query' );

#4 @SergeyBiryukov
12 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

#5 @SergeyBiryukov
12 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from reopened to closed
Note: See TracTickets for help on using tickets.