I'm creating a featured post slider which takes 4 pages or posts from the 'featured' category. I'm trying to use WP_Query, but am having no joy :(
my slider query is:
$ml_featured = new WP_Query(
array(
'posts_per_page' => 4,
'post_type' => array('page', 'post'),
'category__in' => 22
)
);
if( $ml_featured->have_posts() ) {
while( have_posts() ) : $ml_featured->the_post();
// looping
endwhile;
}
else {
// no posts
}
fire_PHP shows the WP_Query contains:
WP_Query(
query =
array(
['posts_per_page'] => 4
['post_type'] =>
array(
[0] => 'page'
[1] => 'post'
)
['category__in'] => 22
)
query_vars =
array(
['posts_per_page'] => 4
['post_type'] =>
array(
[0] => 'wod'
[1] => 'attachment'
)
['category__in'] =>
array(
[0] => 22
)
I'm using Genesis, building upon the sample child theme. In order to display my custom post type 'WOD' on the homepage I've added to functions.php:
add_filter( 'pre_get_posts', 'ml_wods_home' );
function ml_wods_home( $query ) {
if ( is_home() && false == $query->query_vars['suppress_filters'] )
$query->set( 'post_type', array( 'wod', 'attachment' ) );
return $query;
}
as suggested at Justin Tadlock. This works well on its own, but seems to be interfering with the slider query:
Please note that query['post_type'] is overwritten by query_vars['post_type']. In addition, the browser is timing out frequently as I mess around...
I found that Michael Fields had a related issue , posted a solution, (which I think I'm implementing) but its not working for me, and I don't understand it..
What am I missing?! TIA, Tim