I want to add some filter to select needed posts like:
function exclude_post($query) {
if ($query->is_home) {
// Do some PHP code
}
return $query;
}
add_filter('pre_get_posts', 'exclude_post');
How can I add new conditions to existed WP_Query instance $query
?
If you want to modify your query with a filter, you can use $query->set('post_type', 'post');
in your function, just addapt with your parameter.
If you want to modify the main loop, you can use this :
global $wp_query;
$args = array_merge( $wp_query->query_vars, array( 'post_type' => 'product' ) );
query_posts( $args );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With