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 ¯\_(ツ)_/¯

Hi @embark I am working on a competition website using WooCommerce Lottery plugin myself with Bricks. I know this plugin has native integration with Elementor, but I want to move away from Elementor as it is awfully bloated and slow in comparison to bricks.

This is my first time using this plugin, and Bricks, and I’m having difficulty figuring out how to output some of the information from the plugin into a single product template (such as progress bar/amount of tickets sold), and would love to get your help on it as you seem to have been through the same process.

If you could, could you reach out to me via DM and give me some advice? I’d really appreciate it. I’m too new here to DM you (first post) but found your query via Google.

Thanks!