'Building a Post listing with ACF Block that allow to query by taxonomy

I am trying to build an ACF block that allow to display a list of custom post types featuring custom fields.

everything works well if I hard code the category to pull out, but when I want to add a function that allow to pick a category in a dropdown, in order to query dynamically by custom taxonomy, the query is not being parsed. Something wrong in my codes.

The Issue is in the 'Tax_Query' array...

I am using a Taxonomy field in ACF pro in order to display the taxonomies in the dropdown menu of the ACF block.

$argType = get_field( 'loop_argument_type' );
    
    if( $argType == "category" ) :
      $args = array( 
          'orderby' => 'title',
          'order' => 'ASC',
          'posts_per_page' => -1,
          'post_type' => 'chambres',
          'tax_query' => array(
              array(
                  'taxonomy' => 'room_category',
                  'field' => 'term_id',
                  'terms' => get_field('select_room_category', get_the_ID()),
              )
          )
    );

If someone have any suggestions it would be much appreciated 🙏



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source