Multiple criteria on $query->set with results based on OR instead of AND
-
Hi,
I have a code in
functions.php
to show only aside, quote, and image post formats on home page. This one:function mostrar_capa( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'post_format', array('post-format-aside', 'post-format-image', 'post-format-quote' ) ); } } add_action( 'pre_get_posts', 'mostrar_capa' );
It works flawlessly! However, there are a few other type of content that I would like to show on home page alongside those post formats. For instance, posts from a different post type called “podcast”. I tried this modification:
function mostrar_capa( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'post_format', array('post-format-aside', 'post-format-image', 'post-format-quote' ) ); $query->set( 'post_type', 'podcast' ); } } add_action( 'pre_get_posts', 'mostrar_capa' );
It worked, but not as I intended. This code sums both lines (AND), so it only shows posts of “podcast” type that are at the same time an aside, quote, or image. I want those lines to be kind of independent (OR), so if only one criteria/line is true, the post shows up.
(I checked if
$query->set( 'post_type', 'podcast' );
is valid running it by itself. It works.)Any idea how can I do this? My coding level is pretty basic, so I’d appreciate detailed replies.
Thanks!
- The topic ‘Multiple criteria on $query->set with results based on OR instead of AND’ is closed to new replies.