Adding new terms to custom taxonomy

after_setup_theme fires before init, so in this case the code is trying to insert a term into your taxonomy before WordPress is aware that your taxonomy exists! Generally, I feel like init is a better location for both pieces of functionality unless you have a reason to do otherwise. But however you resolve it, if … Read more

Order Categories by Character Count

This is probably more a question about PHP rather than WordPress, and as such may be closed as off-topic for this site. That said, you can usort() to sort an array using a custom comparison function: usort( $listings->loop[‘cats’], function( $a, $b ){ return strlen( $a->name ) – strlen( $b->name ); } ); After the call … Read more

wp_get_object_terms count on taxonomies within an category archive

A simple function to count posts did the trick, but this is one more request in DB : function count_posts_in_cat_by_custom_term( $category_ID, $custom_taxonomy_name, $custom_term_id ){ $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘category’ => $category_ID, ‘tax_query’ => [ [ ‘taxonomy’ => $custom_taxonomy_name, ‘fields’=>’term_id’, ‘terms’ => $custom_term_id, ] ] ); $posts = … Read more

Not recognizing my custom templates in hierarchy

If you register a taxonomy named projects, and create taxonomy-projects.php, the URL mysite.com/projects will not exist. There is no such page in WordPress. If you create a term inside inside that taxonomy, “My Project”, that term will be accessible at mysite.com/projects/my-project and that URL will use taxonomy-projects.php to list all posts that belong to that … Read more

How to orderby Taxonomy Term in a WP Query

You can’t order by taxonomy terms, the very concept breaks down when you try to handle posts that have multiple terms in a taxonomy. You may know that only 1 term will ever be selected but WP_Query isn’t built that way. Instead, keep your taxonomy so that you retain all the performance/theming/Admin UI benefits, but … Read more

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