SOLVED: Struggling with {echo:function()} - only working sometimes

In one part of my site I have {echo:my_function({term_id}, {acf_field})}

It sends the vars to the function, returns correctly, all good.

In another part of the site, I have {echo:my_other_function({term_id}, ‘project’)}
and it echoes back verbatim: {echo:my_other_function(55, ‘project’)}

If I remove the vars and just call the function it works. If i call the function with text (‘55’,‘project’) - it works. As soon as I add dynamic vars I get the {echo:…} statement on screen instead.

So I can pass dynamic vars sometimes, but not others? Why does it work one place an not another?

I want to conditionally hide an element on a term archive, if there are no child terms… If someone can help with that, then I don’t care about the echo: any more!

The code being called is simple, but in case I’ve made a mess, here it is:

function ds_check_term_has_children( $dsTermID = 54, $dsTaxName = ‘project’ ) {
$termchildren = get_term_children( $dsTermID, $dsTaxName );
if ( empty( $termchildren ) ) { return $dsTermID; }
else { return ‘false’; }
}

Thanks in advance.

1 Like

I’m still curious about this… but I’ve found a hacky work-around… a second query-loop, returns max 1 item, the same as the first query, then with just a headline in - which won’t display if there are no posts. Not happy about running a query twice, but also sleep deprived and beyond caring :wink:

Haven’t looked into the how/why but that echo dynamic tag doesn’t work with numbers as the parameters if another dynamic tag is being used as the argument.

Eg…

{echo:get_the_title({post_id})}

Won’t work either.

Hi @wplit ,
Could you help to test it on a Rich Text? I am suspecting the Basic Text has some issues.

Ok, thanks… Shame, but at least I know why and that I’m not going mad… at least not for that reason :slight_smile:

It’s the same for me in rich text, it renders the post_id as the actual number, but doesn’t then echo the function

https://www.loom.com/share/c708844b18bb4dfd9b74ba0c8d57ec66

1 Like

I am experiencing something similar. I have a MB Advanced Taxonomy field. This field stores the taxonomy id. In order to get this id, I created this helper function:

function nod_get_term_id( $field_id ) {
	return rwmb_meta( $field_id )->term_id;
}

The id of the MB Advanced Taxonomy field is “notis_issue”. So I run this “echo”:

{echo:nod_get_term_id('notis_issue')}

If I put this “echo” in a Basic text element, it gives the id “13”, which in this case i correct.

But if I put this in a query loop, under “META QUERY”:
Meta key = notis_issue
Meta value = {echo:nod_get_term_id(‘notis_issue’)}
it does not work, it just gives me this error message:

Warning: Attempt to read property "term_id" 
on string in /home/zzz/wp-content/plugins/wpcodebox/src/Runner/PhpSnippetRunner.php(17) :
 eval()'d code on line 5

Line 5 is “return rwmb_meta( $field_id )->term_id;”.

If I set Meta value= 13, it works fine.

So {echo:nod_get_term_id(‘notis_issue’)} seems not to work in the query loop, but works fine in Basic text element. Why? Bug?

I tested to modify the query loop by using this filter:

add_filter( 'bricks/posts/query_vars', function( $query_vars, $settings, $element_id ) {
   // list all the elements' IDs here
   $elements = array(
       'vcjybg',
   );

   // Check if the element_id is inside the array
   if ( !in_array($element_id, $elements)) {
      return $query_vars;
   }

   // Apply the custom query var
   $query_vars['meta_query'] = array(
      //'relation' => 'AND',
         'notis_issue_clause' => array(
             'key' => 'notis_issue',
             'value' => 13,
             'compare' => '=',
             'type'  => 'numeric',
         ),
   );

   // return the modified query var
   return $query_vars;
}, 10, 3 );

And this works!

But how can I use the function nod_get_term_id(‘notis_issue’) together with this filter?

Hey guys,
Just to let you know: we’ve added the issue to the bug tracker.

Best regards,
timmse

3 Likes

@timmse I just encountered the same problem and found this post. I don’t see it on the list for 1.8 beta, do you have any status/ETA?

Hi guys,

We’ve fixed this issue in Bricks 1.8 beta 2, now available as a manual download in your account.

Please let us know if you are still experiencing issues.

As with any beta release, please do not use it on any production/live website. It is only meant for testing in a local/staging environment.

2 Likes

Working well for me so far :slightly_smiling_face:

1 Like

I confirm that it works for me too :slight_smile:

The only exception is when I use Dynamic Data Tags from Bricksforge like {brf_form_calculation}. But this isn’t Bricks but Bricksforge related (@Daniele). Could someone with a copy of Bricksforge confirm that?

Thanks for letting me know! Will check that asap and come back to you :+1:

Hi, I’ve been trying this on v1.8 (full production release) and think I’m experiencing the same issue. Description is here: Bricks Community | Facebook and I’ll be happy to help replicate if useful - please just let me know. Thanks!

Hi Martin,
Welcome to the forum!

Would you be so kind as to provide a screen recording showing and explaining your setup?

Best regards,
timmse

Thanks for the response Timmse, it’s a client site but I’ll try to replicate on a local Dev environment for you and record it.

the {echo:my_function} is not working again for me. It used to work. I can put the same code in a “Code Element” and it works.

Bricks 1.9.4

It seems to be an issue with WP Codebox. Very supprised!

WP Codebox can get into a state where there is an error that was not cleared. The only indication is that the script item turns red. At that point nothing works out of that file item. If you click on the item in red - THEN - you can clear it - reset it - even if the reason for the error state no longer exists.

Live and learn :slight_smile: