Add a term to list in block editor taxonomy sidebar
The problem is you are passing “term_id” as 0 in your code. Use -1 instead!. It will definitely show up in the Block Editor. I guess this is a bug of Gutenberg though.
The problem is you are passing “term_id” as 0 in your code. Use -1 instead!. It will definitely show up in the Block Editor. I guess this is a bug of Gutenberg though.
You could use pre_get_posts to conditionally add the tax_query depending on post-type, here’s a simple example. <?php function wpse_377928( $the_query ){ $post_type = $the_query->get(‘post_type’); if ( ‘type_a’ === $post_type ) { $tax_query = [ [ ‘taxonomy’ => ‘tax-1’, ‘field’ => ‘term_id’, ‘terms’ => array(11, 12, 13), ] ]; } elseif ( ‘type_b’ === $post_type ) … Read more
Did you try this? Here: unregister_taxonomy_for_object_type() Read more: https://developer.wordpress.org/reference/functions/unregister_taxonomy_for_object_type/ function unregister_portfolio_cat_for_portfolio() { unregister_taxonomy_for_object_type( ‘portfolio-cat’, ‘portfolio’ ); } add_action( ‘init’, ‘unregister_portfolio_cat_for_portfolio’ );
You should no longer use the legacy function parameter format. Instead, as the documentation says, use the get_terms( $args ) format: Since 4.5.0, taxonomies should be passed via the ‘taxonomy’ argument in the $args array: $terms = get_terms( array( ‘taxonomy’ => ‘post_tag’, ‘hide_empty’ => false, ) ); And as for getting only the terms assigned … Read more
I solved this issue after Rup in one of the comments pointed out that the parent categories dropdown was most likely the culprit. Sure enough, that was the issue. It appears WordPress was attempting to populate the dropdown with 15,000 items which were causing an excessive query to be made to retrieve those items. The … Read more
How about doing it this way: <?php // Get (at most) 2 “product” posts in the child term. $posts = get_posts( array( ‘post_type’ => ‘product’, // just change the post type if it is not “product” ‘posts_per_page’ => 2, $taxonomy_name => $child->slug, ) ); // If there’s exactly 1 post, use the post permalink. if … Read more
Going by what @JacobPeattie said, that they are still set but empty you need to change the conditional login to check for empty. In our previous discussion I wrote this conditions if ((isset($_POST[‘categoryfilter1’]) && !empty($_POST[‘categoryfilter1’])) && (isset($_POST[‘categoryfilter2’]) && !empty($_POST[‘categoryfilter2’]))) { // both properties are set and have value (not empty) } elseif ((isset($_POST[‘categoryfilter1’]) && !empty($_POST[‘categoryfilter1’])) … Read more
In my archive-product_category.php I have this (relevant) code Are you sure that’s the correct name? Because for a post type archive, it should be archive-al_product.php and for a taxonomy archive page, it would be taxonomy-product_category.php. Anyway, (as I said in the comments) if you want to target the taxonomy archive page, you should use is_tax(), … Read more
Try to use get_term_by(), where first argument is a field, in your case – name. Second is your value. I used esc_attr() to make it secure. Third one is taxonomy, as example I put here category. if ($_SERVER[“REQUEST_METHOD”] == “GET” && $_GET[‘fname2’] && $_GET[‘fname’]) { $nameb = get_term_by(‘name’, esc_attr($_GET[‘fname2’]), ‘category’); $namea = get_term_by(‘name’, esc_attr($_GET[‘fname’]), ‘category’); … Read more
If you want to filter the query for a taxonomy archive, you should check if the query is for that archive: if ( $query->is_tax( ‘book_cat’ ) ) { $query->set(‘orderby’, ‘meta_value’); $query->set(‘meta_key’, ‘published’); $query->set(‘order’, ‘ASC’); }