List posts grouped by children of a custom taxonomy
List posts grouped by children of a custom taxonomy
List posts grouped by children of a 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
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
If you mean, how to change the link’s text, then you can change it when you register your taxonomy, by setting the back_to_items label to whatever text you like. Excerpt from the documentation: ‘back_to_items’ – the text displayed after a term has been updated for a link back to main index. Default is __( ‘← … Read more
I am echoing the “procedures” term I expect to get this meta field get_term() returns a WP_Term object which by default does not include any metadata, even for registered meta keys. So registering a meta key does not automatically add it to the term object, but registering a meta key has 2 main benefits: You … Read more
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
It seemed like you did not call wp_reset_postdata() which in short, restores the context of the template tags (e.g. the_title() and get_the_title()) from a secondary query loop back to the main query loop. More details at https://developer.wordpress.org/reference/functions/wp_reset_postdata/#more-information. So basically, you just need to call wp_reset_postdata() like so, and then the issue in question would disappear: … Read more
Instead of checking against the template, you should use is_tax() which is one of the conditional tags in WordPress. So in your function, you just need to use is_tax( ‘state’ ) in place of is_page_template( ‘taxonomy-state.php’), and your asset would only be loaded on the archive page for your custom state taxonomy.
It’s not limiting to 5 posts That’s because the posts_per_page arg should actually be in the same level as the post_type arg and not put inside the tax_query array. I.e. $args = array( ‘post_type’ => ‘oferta’, ‘posts_per_page’ => 5, // add it here ‘tax_query’ => array( array( ‘taxonomy’ => ‘categoria’, ‘posts_per_page’ => 5, // NOT … Read more
Links in archive not including taxonomy parameter