Support

Account

Home Forums ACF PRO Custom Query: Product Category > User Field

Solving

Custom Query: Product Category > User Field

  • Hello,

    I’m an ACF pro customer and I’m hoping to get my hands on a custom query that will show only WooCommerce products in a category that are assigned to a User using the ACF User field.

    For instance, there is a Product category named “Category X,” and in the User custom field that appears on its Product category settings page, I selected “User X,” creating a relationship between the “Category X” and “User X.”

    Now I need a query to show only the products (“Category X) for “User X” when they are logged in. This query needs to work for any particular user (I will be assigning different product categories to different users).

    I’m trying to use Dynamic.ooo to set this query, but unfortunately the options don’t allow it, so it must be custom.

    Preferred Query ID: user_category

    ACF Settings:
    Field Type: User
    Filter By Role: Customer
    Return Format: User Array (or whatever works best)
    Show this field group if: Taxonomy is equal to Category (product_cat)

  • Also, I failed to mention that the User custom field name is category_user

  • I tried the below but it is not working.

    $args = array(
        'posts_per_page' => -1,
        'post_type' => 'product',
        'taxonomy' => 'product_cat',
        //Tries to show products from categories where current user ID is in the category_user field
        'meta_query' => array(
          array(
            'key' => 'category_user',
            'value' => '"' . $current_user->ID . '"',
            'compare' => 'LIKE'
          )
        )
      );
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.