Nested loopers help needed

Hi. I tried to search forum for help but couldn’t find answer for my problem.

I have a base looper and it lists all products from CPT “Products” based on specific taxonomy. This works fine with following query builder:

Posts: Products
Taxonomy: Cleaning
Order by: Date Ascending

Next, I have an inner looper inside base looper for each product. It should list any files from CPT “Documents” if they are in relationship with current product. “Documents” has relationship field “product_ids” (with option to choose multiple products) and in ACF I’ve checked return format to be “Post ID”. For example if there’s two products connected to any file, “product_ids” would return value “123, 345”. Below
are my settings for inner looper and for reason I don’t know all files are always listed for all products so comparing doesn’t work.

Inner Looper Query Builder:

Posts: Documents
Meta Values:
Meta Key: product_ids
Comparison: Like
Meta Value: {{dc:looper:field key=“ID” depth=“1”}}

I have attached screen capture of two first items from the page. As seen in image, base looper first fetches product #735 and prints it’s details, then for connected files it starts the inner looper and finds a document #809 which
has product #735 in file_ids which means it’s connected to the product and should be printed, and that’s fine.

But, then we go to second product #736 which is not included in product_ids yet still same document #809 is listed the very same way. And same happens with any other product.

I am also printing out depth 0 and 1 and they both show correct values, depth 1 prints out current base looper parent product ID and depth 0 current inner looper document ID.

Am i doing/understanding something wrong with ACF relationship field and meta value ?

Hello @jonecky816739,

Thanks for writing to us.

In order to help you with your concern, please share your details in a secure note. Please provide the following details

  • WordPress Login URL
  • Admin-level username and password
  • Exact page URL

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

Thanks

Details provided, thanks for your very fast reaction.

Hi @jonecky816739,

As per the description, the field name should be liittyvat_tuotteet, as in the nested looper, a different field has been used.

Can you please check by using the correct field name? If that does not help, please copy your live site to a staging server so we can troubleshoot freely without breaking your live site.
And give us access to the secure note, including:

– WordPress Site URL & Login URL
– WordPress Admin username/password

To create a secure note, click the key icon underneath any of your posts.

Thanks

Hi. It was liittyvat_tuotteet but I made some checks and forgot to change it back.

BUT, good thing is a sorted it out myself. It works with given metavalue {{dc:looper:field key=“ID” depth=“0”}} which kind of doesn’t make any sense to me but it works. with depth 1 or -1 query matches chosen document to all posts which means those values give empty value in return so LIKE matches everything. With depth 0 query gets parent looper ID.

Also, one thing I found out. query doesn’t bring correct listing in Cornerstone edit screen but only on public page.

So basically I have no idea why if works but it works. Problem solved.

Hello @jonecky816739,

Thanks so much for the update, glad to know that things are well for you.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.