Support

Account

Home Forums Backend Issues (wp-admin) WP_Query using ACF Taxonomy Category Reply To: WP_Query using ACF Taxonomy Category

  • I really do not see anything seriously wrong, the only thing I can think of is that you either have the wrong taxonomy name or that the values your trying to use in the query are not integers

    
    // this field can return either a single category or multiple
    // ensure that you are only getting the ID values of the terms and not term objects
    $categories = get_field('project_slider_category', false, false);
    if ($categories) {
      if (!is_array($categories)) {
        $categories = array($categories);
      }
      // make sure all values are integers
      $categories = array_map('intval', $categories);
    }
    
    $args = array(  
        'post_type' => 'project',
        'post_status' => 'publish',
        'posts_per_page' => 8, 
        'orderby' => 'title', 
        'order' => 'ASC',
        'tax_query' => array(
          array(
            // make sure the category name is "categories"
            'taxonomy' => 'categories',
            'terms' => $categories
          ),
        ), 
    );
    
    $loop = new WP_Query( $args );