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 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.4 |
Component: | Query | Keywords: | close |
Focuses: | Cc: |
Description (last modified by )
As I said in this forum topic: http://wordpress.org/support/topic/custom-posts-query-does-not-work-on-index-with-paged-var?replies=4, also maybe related to this: #21417.
Change History (5)
#2
@
12 years ago
- Keywords close added; 2nd-opinion dev-feedback removed
- Severity changed from major to normal
#3
@
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' );
Note: See
TracTickets for help on using
tickets.
The problem is the use of
query_posts()
here. You should hook into thepre_get_posts
, sincequery_posts()
is too late.