BUG Pro 4.3.3 - Can't pass JSON to custom loopers

It seems that in the latest version of Pro you can’t pass a {{DC:…}} in JSON to a customer looper and use the value that pulls into the function in the code. Essentially we can’t use custom loopers at all for what they are needed for.

Example:

**JSON passed to custom loop**
{
   "cat":"{{dc:term:id}}"
}

**Custom Looper**
add_filter('cs_looper_custom_subcat', function($result, $args) {
    $term_id= $args['cat'];
    $trm=get_term( $term_id, 'category' );
    return ['parent_cat'=>$trm->parent];
}, 10, 2);

**Display the result**
{{dc:looper:field key=“parent_cat”}}

So the above code will not work.

If I echo $args[‘cat’] the code echos the correct id that is passed to the looper but the code does not work. It then returns an empty array. If I change $term_id= $args[‘cat’]; to $term_id= 5; (The id of the cat that is passed from the JSON) then the code works and does what is expected.

So if I hard code the term ID then {{dc:looper:field key=“parent_cat”}} shows the expected result but if I use the arg from the JSON then {{dc:looper:field key=“parent_cat”}} is empty.

Hopefully you can push a fix before the latest theme is pushed as this is a massive problem.

Hey @urchindesign,

I’m sorry, the JSON provider wasn’t designed to support dynamic content inline like that. The most you can do is put something like: {{dc:post:meta key="something"}} and it will expect the value retrieved to be valid JSON. I can make a note about exploring that possibility, but it likely isn’t something we’ll be getting to near term.

Ok thanks. I appreciate the feedback. This code was actually based on a snippet provided by your support.

Just wondering how we pass dynamic content to custom loopers. I would prefer not to be doing something that is going to break in an update.

At the moment I’m finding it quite tricky to build out decent Woo pages with all the limitations and difficulties around passing dynamic content to loopers.

With Woo there are settings under appearance -> customize -> woo where you can set the shop to display categories, the categories to display sub categories and products etc. One would expect these to create the correct loops to be available in the layout builder woo archive pages but they don’t seem to work.

If we don’t use the layout builder then these pages work as expected and show what has been set in the settings.

But in the layout builder the best I can is simply show all categories including all sub categories so the loop doesn’t seem to follow the settings. But if I don’t set the settings to show all products then my loop doesn’t bring out the products which is really strange as that seems to imply that is following the settings in some instances.

Hi @urchindesign,

I’m sorry for not thinking to mention this earlier, but you can invoke dynamic content PHP side like this:

$term_id = cs_dynamic_content( $args['cat'] );
2 Likes

Brilliant. I’ve been using php in my functions but being able to pass dynamic content will make life much easier! Thanks.

You’re welcome!