ACF Checkbox Field

Hi theme.co

Is it me or the ACF checkbox field has something special to loop through?

I created an ACF checkbox field to show in both posts and products backend. This is to show suggested products under each blog post.

Here’s the structure. I used the query builder.

In the row, I looped through the post field and added the ACF custom field key and value that “EXIST”; in the column, I consumed the field; and in the div, I looped and consumed the product field and added the same field’s custom key and value that “EXIST”.

Having checked the box under each product for the same product, I then check the recommended products boxes for each blog post.

I created a checkbox field because for some posts there are more than one product I want to recommended.

This is not working. What am I doing wrong?

Thanks in advance

Hey @hjaffer,

Thanks for reaching out!

In order for us to help you with your issues, we need to check and investigate your setup properly. To do that, please give us the following information in a Secure Note.

  • WordPress Login URL
  • Admin level username and password

You can find the Secure Note button at the bottom of your posts.

Thank you.

Access geanted.

Hello @hjaffer,

I am seeing this one:
Screenshot 2024-03-02 at 10.29.59 AM

You will have to use Looper Provider Dynamic Content where {{dc:acf:post_field field="product_recommendation"}}

You should be using {{dc:looper:item}} to display each return value.

Hope this makes sense.

Hi @ruenel,

Do you mean to say that the first looper in the row should be {{dc:acf:post_field field=“product_recommendation”}} and the second looper in the element should be {{dc:looper:item}}?

I tried that and it didn’t work.

Can you explain more please?

Hey @hjaffer,

Your custom field is product_recommendation right? This field returns more than one value therefore you will have to run a loop to display all of those values. You only need 1 loop to display all those 3 item values.

Looper Provider Dynamic Content `{{dc:acf:post_field field="product_recommendation"}}` 
     Looper Consumer
           Headline with `{{dc:looper:item}}` in it

Best Regards.

Thanks @ruenel, something started to work now.

The image doesn’t appear when I set this up. What changes do I have to make to get the product image?

Fo title, I need the product title to appear instead of the field value. How do I change the {{dc:looper:item}} to get the product title instead?

Hello @hjaffer,

I am just confused because if you want to display the ACF field {{dc:acf:post_field field="product_recommendation"}}, it will only display bmb, bsi and adj. It will not display product items. What are you trying to display for the “Suggested Products” section? Please give further clarifications.

Thank you.

Hi @ruenel,

I want to display product cards like what’s availabe in section 2. Section 2 uses tags and a query string to display product recommendations. I want to stop using tags and rather use a custom field.

Thanks

Hey @hjaffer,

How are the bmb , bsi and adj values related to your product items? Once you figure this out, you can use a Looper Provider Query String or the Looper Provider Query Builder to display the product items as your recommendations.

Best Regards.

@ruenel these are ACFs that shows up under posts and products from the same ACF group.

Hey @hjaffer,

Yes, that is the ACF field for your products. You are trying to display recommended product items with the same ACF field like when a product is tagged as 'BMI`?

If that is the case, then you will have to use the Looper Provider Query String and then use the {{dc:acf:post_field field="product_recommendation"}} dynamic content as the custom meta query for the products.

Example query argument:

 $args = array(
  'post_type' => 'product',
  'posts_per_page'      => 4,
  'offset'              => 0,
  'ignore_sticky_posts' => true,
  'post__not_in'        => array( '{{dc:post:id}}' )
  'meta_query' => array(
    'meta_key' => 'product_recommendation',
    'meta_value' => '{{dc:acf:post_field field="product_recommendation"}}',
    'meta_compare' => 'IN',
  ),
);

The above is NOT a query string. Kindly check out this old thread for more details on how you can create the query string:

Best Regards.

@ruenel a correction. I’m trying to display recommended product items with the same ACF field like when a post is tagged as BMB, BSI or ADJ or all. So I’m trying to display products in posts.

Hello @hjaffer,

Yes, the above query arguments will return product items with the same ACF field as the current post tagged as BMB, BSI, or ADJ. This query argument is the one you can use to create a query string for your Looper Provider.

Hope this makes sense.

@ruenel so I added the looper and consumer to the column.

For looper, I used the following query string:
post_type=product&post_status=publish&orderby=none&posts_per_page=4&ignore_sticky_posts=1&meta_query[0][key]=product_recommendation&meta_query[0][value]={{dc:acf:post_field field="product_recommendation"}}&meta_query[0][compare]=IN&offset=0

I can’t have it to work.

Help!

Hello @hjaffer,

Your query string is incorrect. It should be:

post_type=product&posts_per_page=4&offset=0&ignore_sticky_posts=1&post__not_in%5B0%5D=%7B%7Bdc%3Apost%3Aid%7D%7D&meta_query%5Bmeta_key%5D=product_recommendation&meta_query%5Bmeta_value%5D={{dc:acf:post_field field="product_recommendation"}}&meta_query%5Bmeta_compare%5D=IN

Kindly let us know how it goes.

I don’t know why nothing is working.

Hey @hjaffer,

You should only have 1 Looper Provider with the query string below:

Hope this helps.

@ruenel this returns all products in all posts. What I’m trying to do is to return products that I checked in {{dc:acf:post_field field=“product_recommendation”}} under each post.

Hello @hjaffer,

The query is in place the problem is that there is no connection between the product_recommendation post meta and the product meta. I made some changes to make it work. Please check the URL in the secure note.

Thanks.