Support

Account

Home Forums Front-end Issues Archive Page, Filter by Custom Fields inside ACF Relationship Reply To: Archive Page, Filter by Custom Fields inside ACF Relationship

  • Currently, I can only filter the Stores by the custom fields directly associated with the Stores post type.

    This is always. In order to filter the store by the field of a product that field would also need to be stored associated with the store.

    however… what I’m seeing is that you want to filter the products while showing the store and not the stores…..

    
    // get the product ID values
    $product_ids = get_field('products', false, false); // acf relationship
    // by setting the 3rd parameter to false you get just a list of post IDs
    
    if ($product_ids) {
    
      // ensure that products is an array, 
      // and that the values are integers
      if (!is_array($product_ids)) {
        $product_ids = array($product_ids);
      }
      $product_ids = array_map('intval', $product_ids);
    
      // do your own query to get the posts
      // I only include the necessities here 
      $args = array(
        'post_type' => 'product',
        'post__in' => $product_ids,
        'meta_query' => array(
          array(
            'key' => 'status'
            'value' => $_GET['product_status']
          )
        )
      );
    
      $products = new WP_Query($args);
      if ($products->have_posts()) {
        while ($products->have_posts()) {
          $products->the_post();
          // output product data here
        }
        wp_reset_postdata();
      }
    
    } // end if products
    

    Of course you’d also need to adjust the store meta query to skip the fields associated with the product.