Different options per post type in WP_Query

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

Get taxonomy name for the current post

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

Ajax filter button display all posts

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

sort CPT on Custom Taxonomy Archive page

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

get term id from term name

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