get_the_terms() not returning expected result

If you are trying to get the number of terms your post have, then you should use wp_get_post_terms(). $sizeCount = count(wp_get_post_terms($post->ID, ‘sizes’)); $colorCount = count(wp_get_post_terms($post->ID, ‘colors’)); echo $sizeCount . ‘ ‘ . $colorCount;

`get_terms()` with `child_of` and `childless` combined

OK, so this is what I came up with: function get_childless_term_children( $parent_id, $taxonomy ) { // get all childless $terms of this $taxonomy $terms = get_terms(array( ‘taxonomy’ => $taxonomy, ‘childless’ => true, )); foreach( $terms as $key => $term ) { // remove $terms that aren’t descendants (= children) of $parent_id if( !in_array( $parent_id, get_ancestors( … Read more

Taxonomy term page going to 404

Following @CraigWayne’s suggestion to use Query Monitor… Message: “Use of undefined constant term_name – assumed ‘term_name’”. Count: 1. Location: wp-content/themes/elegant/taxonomy-source.php:38. Caller: wp-includes/template-loader.php wp-includes/template-loader.php:74. Component: Core. >>>>> Line 38 in taxonomy-source.php included “” it was objecting to term_name in my taxonomy-source theme file; I changed it to $term = get_queried_object(); followed by name; ?> The takeaway … Read more

Ajax is not working in a loop

Your code has var getid = $(‘#my-categorychecklist input:checked’).last().val(); see the .last(), that’s why you’re only getting the last item Also, why do you have the same thing in getid and matchid? You need to store the selected categories in an array and loop through them, try something like: var selected_cats = $(‘#my-categorychecklist input:checked’).map(function() { return … Read more

Include Parent Term in wp_list_categories

Try this, which worked well for me: $term = get_queried_object(); $children = get_term_children( $term->term_id, $term->taxonomy ); $has_children = ( ! is_wp_error( $children ) && ! empty( $children ) ); // Has children, or no parent. if ( $has_children || ! $term->parent ) { $parent =& $term; // reference to $term // No children, but has … Read more