So I have a weird issue.
I have a custom looper provider that works 100% when I hard code the value of my variable.
The problem is that as soon as I pass the variable to the code and dynamically assign the value of the arg to the variable then the code does not work. i.e. $term_id= $args[‘cat’];
The strange thing is that if I echo the variable then it echos the correct value. If using your exact code it does not work. echo $args[‘cat’]; (gives me the correct ID)
See example, to keep things simple I tried taking code from another forum post and that code won’t work. (Reading elements of a looper)
**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.