Query Loop to filter by ACPT/ACF Field Group

Hello,
I want to filter a product in woocommerce based on a custom field group (weekly_deal) I created. If the checkbox is set, I want to build a query loop, to display the product on the homepage. It seems rather simple to me, but I cannot get it to work.



I cannot get the filter to work though to display the product. there will only be one product at a time with this checkbox set.

I know how to create query loops for custom post types, and that works well, but I never built a loop around a specific field to be set

I set the feature image, but I this is not the correct product being displayed. This one also has not set the flag, so I assume it is feeding in, because of the template settings to use all products.

Order by: “meta value” is a display filer to sort the output.

Little more below in the query settings is “meta query”. This should allow you to output based on the meta field.

Other way might be to create a special taxonomy for it as there is gonne be just 1 product init.
Or make it sticky

S4

I am not sure what the difference is between meta key and meta value and how do I check for a set checkbox field

Your meta key would be {weekly_deal} and for value, depending on what the checkbox field has as input. 0 or 1, true or false

So meta key should check out to be equal to true (or 1)

For using the correct meta key, sometimes they are without the { } signs. Not sure why and i don’t use metabox but stick to acf. Weird it has no dynamic data input.

To see the checkbox value, try outputting it in a text field.

aaaaah that is so frustrating… I tried that too, but nothing gets filtered. I also tried the taxonomy. with the same effect:


I see that the product field group is correctly set, and set the textfield to its output as you suggested:

THere it shows true

Though the dynamic data selector had this : {acpt_product_weekly-deal-config_weekly-deal}

Are they in the same posttype?

For taxonomy, use a normal query for that, add Terms (include) for the weekly
This include only that term and excludes all others.

For the meta query thing,
Meta key goes without the { } signs
See meta query as a more advance filter on your normal query
If you use this to compare against another field, it does require { } for meta value.

About the data selector: Though the dynamic data selector had this : {acpt_product_weekly-deal-config_weekly-deal}
I think its a metabox thing.
Acf just has it as a unordered list, while metabox sort of uses a breadcrumb type like selector.

In this case I am using ACPT, but I would assume, that doesn’t make a big difference? Yep all are in the same posttype (products).

For the taxonomy it worked perfectly with the “add terms include” field. Now it shols the product. THough I would assume, this should be able to be replicated also with the field group and a meta query

I think for meta key: acpt_product_weekly-deal-config_weekly-deal
Meta value: True
Compare: Equal

is supposed to work. But this takes trying.

1 Like

I will go for the taxonomy for now. Thanks for your help, Ferry!