Show Post from parent category (custom taxonomy) ONLY!

Any tax_query can take an include_children argument (see Codex) that defaults to true. So just add that to your code and it should work: <?php $args = array( ‘posts_per_page’ => 100, ‘post_status’ => ‘publish’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘ait-dir-item-category’, ‘field’ => ‘id’, ‘terms’ => 75, ‘include_children’ => false ) ), ‘post_type’ => ‘ait-dir-item’ … Read more

Custom Taxonomy Meta Admin Column

I managed to work it out. Seems like the filters only work when wrapped in an ‘admin_init’ action. My final code to add an admin column for the custom taxonomy meta ‘front_page’ to the custom taxonomy ‘shopp_department’ in my themes’ functions.php // Register the column function department_add_dynamic_hooks() { $taxonomy = ‘shopp_department’; add_filter( ‘manage_’ . $taxonomy … Read more

Rewrite rule for custom taxonomy

I came up with this with the add_rewrite_rule(): add_rewrite_rule(‘^recipes-with-([^/]*)/?’,’index.php?ingredient=$matches[1]’,’top’); I did some testing for the above, and it works well when you use it for one taxonomy at time. Here is the code from my functions.php: add_action( ‘init’, ‘create_ingredient_tax’ ); function create_ingredient_tax() { register_taxonomy( ‘ingredient’, ‘post’, array( ‘label’ => ‘Ingredient’, ‘hierarchical’ => true ), array( … Read more

wp_options table value

The only really interesting (and very important) part of the 3rd query is this: ‘project_location_children’, ‘a:7:{i:22;a:1:{i:0;i:23;}…etc…}}’ The a:n:{i:n; etc } stuff is a serialized PHP array. WordPress – for some historical reason – keeps track of term children in one option entry per taxonomy term. The painful thing is, that a lot of people don’t … 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