How to Get All Taxonomies AND All Terms For Each Taxonomy With Post Count Zero

You can do this with just get_terms – this allows you to fetch all (or some) of the terms from one (or more) taxonomies. By default it excludes ’empty’ terms, so you’ll need to set the arguments appropriately. //Array of taxonomies to get terms for $taxonomies = array(‘category’,’post_tags’,’my-tax’); //Set arguments – don’t ‘hide’ empty terms. … Read more

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

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)