Functions.php code not working with Bricks

Tried:

{echo:get_post_meta( {post_id}, 'percentage_of_tickets_sold', true )}%

But think I was trying to be too clever there.

Thanks again for helping me get to this point!

Yes! I was simply trying to find, where is this meta hiding :wink: So now let’s talk about, how to make it dynamic for each and every post.

Yeah, we can’t nest functions like that with echo tag (at least I don’t know how to do it). So we have other options, depending on whether this field shows in the dynamic data selection now.

  1. If it does show there, then simply use it as a dynamic data
  2. If it doesn’t, then you need to use
    • a function (inside functions.php) that you will output with {echo:function_name}
    • or a code block with php returning the meta value

If it’s second case then I would go with functions.php as you already have code there. I would add

function get_percentage_of_tickets_sold() {
   return get_post_meta(get_the_ID(), 'percentage_of_tickets_sold', true );
}

Then in basic text element you add {echo:get_percentage_of_tickets_sold} and it should work.

1 Like

I will give this a try in the morning and then give an update. I just wanted to say a massive thanks for your help this evening.

I look forward to giving the above a go, tomorrow!

1 Like

Just gave the code a go - Worked perfectly! Thank you so much for your support with this. Really appreciated man.

Side-note, should it be THIS difficult in Bricks? Just a thought.

I guess that the difficulty comes from how this meta is created. If it was a native custom field or something created with ACF (or similar plugin) then you would simply have it on the dynamic data list. I understand that in the other builder it worked right away. Still, at some point you yourself said that this field wasn’t created for one post, so maybe now using simple {cf_field_name} dynamic data would work as it should per documentation ¯\_(ツ)_/¯