Opened 9 months ago
Closed 9 months ago
#21522 closed defect (bug) (invalid)
Custom posts query does not work on index with paged var
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Query | Version: | 3.4 |
| Severity: | normal | Keywords: | close |
| Cc: |
Description (last modified by SergeyBiryukov)
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)
comment:1
SergeyBiryukov — 9 months ago
- Description modified (diff)
- Keywords close added; 2nd-opinion dev-feedback removed
- Severity changed from major to normal
- 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
SergeyBiryukov — 9 months ago
- Resolution fixed deleted
- Status changed from closed to reopened
comment:5
SergeyBiryukov — 9 months ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from reopened to closed
Note: See
TracTickets for help on using
tickets.

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