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

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

get_the_terms inside save_post gives old terms

This issue shouldn’t happen if you’re using the classic editor, however, if you’re using the block/Gutenberg editor which uses the REST API, then that issue can be fixed by using the wp_after_insert_post hook instead. Excerpt from https://make.wordpress.org/core/2020/11/20/new-action-wp_after_insert_post-in-wordpress-5-6/: The new action wp_after_insert_post has been added to WordPress 5.6 to allow theme and plugin developers to run … Read more

Trying to list custom categories in custom post type [closed]

Try this, you can’t just throw a conditional block inside an echo statement. If you really need to it has to be a shorthand if-else, but for visual purposes I have put the statement outside the loop: $taxonomy = ‘product-categories’; $tax_terms = get_terms( $taxonomy ); foreach($tax_terms as $tax_term) { $terms = apply_filters( ‘product-categories-images-get-terms’, ” ); … Read more

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