Add_query_arg + two times the same argument?

Nilambar’s comment solved this for me. “You can pass two values as comma separated in a single parameter events. And later parse value correctly in your page. – Nilambar” I use this to get posts with tag1 OR tag2: echo ‘<a href=”‘.esc_attr(add_query_arg( ‘events’, ‘tag1,tag2′)).'”>Linkname</a>’; And to get all posts with tag1 AND tag2 simply use … Read more

How do I search WordPress by different fields without a plugin?

I found a solution that allows me to search posts by tags and categories while still searching title and content. This does exactly what I was looking for. Credit: https://rfmeier.net/include-category-and-post-tag-names-in-the-wordpress-search/ add_filter( ‘posts_join’, ‘search_join’, 10, 2 ); /** * Joins the terms, term_relationship, and term_taxonomy tables. * * @global $wpdb * * @param string $join The … Read more

Taxonomy posts on Archive page

What you are doing Your foreach is nested inside while (have_posts()) : the_post();. This while loop, loops through each of your posts (in the genre ‘hip_hop’). So for each post in the genre ‘hip_hop’, you find the post’s taxonomy terms for the taxonomy ‘sub_genre’ (this is the contents of $cam_brands). Then, for each associated term … Read more

Group Custom post type in a page by its taxomony tag

If I follow your question correctly you could use a nested query loop, that is looping through your taxonomy terms and then doing a WP_Query loop for each one. There is a more complicated approach using custom SQL and a filter but the following example is what I would go for: $terms = get_terms(“locations”); $count … Read more

SQL Statement generated by WP_Query not producing expected results

It looks like this section: AND (wptom_posts.post_status=”publish” OR wptom_posts.post_author = 1 AND wptom_posts.post_status=”private”) is not tied in at all to the two different query conditions… Perhaps the original code should be three conditions for part 1: array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘operator’ => ‘IN’), array( ‘taxonomy’ => ‘post_tag’, ‘field’ … Read more

query multiple taxonomy and show post count

I’m sure that a custom sql query would work much better but here is an option using the WordPress Tools available //first get all categories $categories = get_terms( ‘category’, array( ‘orderby’ => ‘count’, )); //then create an array for easier processing foreach ( $categories as $cat ) { $slugs[] = $cat->slug; $counts[$cat->slug][‘count’] = $cat->count; } … Read more

Counting number of posts with Category B in Category A

Make use of the WP_Query class, namely the tax_query and fields parameters. Get the count from the $found_posts property. Please note, this is exemplary code. $query = new WP_Query( [ ‘post_type’ => ‘games’, ‘tax_query’ = [ ‘relation’ => ‘AND’, [ ‘taxonomy’ => ‘game_status’, ‘field’ => ‘slug’, ‘terms’ => [ ‘beaten’ ], ], [ ‘taxonomy’ => … Read more

How to build a multi-taxonomy, multi-term query based on user input

I am a little fuzzy on specifics of technical side, but I think general outline would be following: Interface – you will need to either submit this as form by button or JavaScript. Query variables – you will need to register custom variable(s) via query_vars filter so your custom data is not discarded from URL. … Read more

How to choose which template to be used for multiple taxonomy query?

I’m not sure if this the best method, and I would like to hear some other suggestions! This will alter the template to some pre-defined template if two or more taxonomies are being queried. You can hard-code the taxonomies to check or use get_taxonomies: /* * Checks to see if more than one of (certain) … Read more