WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#21522 closed defect (bug) (invalid)

Custom posts query does not work on index with paged var

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

Change History (5)

comment:1 SergeyBiryukov2 years ago

  • Description modified (diff)

comment:2 ocean902 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.

comment:3 adrian72 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' );

comment:4 SergeyBiryukov2 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:5 SergeyBiryukov2 years ago

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