[Solved] Get posts that matches specific terms of multiple custom taxonomies

I’ve finally solved this problem. I’m copying the code because it may help someone 🙂 I’ve found the solution by populating an arrray and checking if a brand is or is not there, so I only get each brand one time. <?php //Query to match department $args = array( ‘tax_query’ => array( array( ‘taxonomy’ => … Read more

[Solved] When to use WP_query(), query_posts() and pre_get_posts

You are right to say: Never use query_posts anymore pre_get_posts pre_get_posts is a filter, for altering any query. It is most often used to alter only the ‘main query’: add_action(‘pre_get_posts’,’wpse50761_alter_query’); function wpse50761_alter_query($query){ if( $query->is_main_query() ){ //Do something to main query } } (I would also check that is_admin() returns false – though this may be … Read more

[Solved] When should you use WP_Query vs query_posts() vs get_posts()?

query_posts() is overly simplistic and a problematic way to modify the main query of a page by replacing it with new instance of the query. It is inefficient (re-runs SQL queries) and will outright fail in some circumstances (especially often when dealing with posts pagination). Any modern WP code should use more reliable methods, like … Read more