Iâm definitely new to Bricks and donât know a great deal about php, however. I checked the complete code you provided in PHP Checker and it shows an error. Checking just the Function the code appears to be fine.
Is the code you have provided the COMPLETE code in your functions.php file??
And have you got the Bricks Child Theme activated??
The code works in the child theme functions.php file. But I canât get this newly created meta value âpercentage_of_tickets_soldâ to show in Bricks - am I missing how to do this correctly?
If you want to output your postâs custom field, you should use dynamic data. Check article on how to use dynamic data in Bricks under âNative WordPress custom fieldsâ section.
Thanks for the guide - pointed me in the right direction!
I had tried the dynamic data previously without any luck.
I am using {term_meta:percentage_of_tickets_sold} but this doesnât render any dynamic date.
Checking the database, I found: âpercentage_of_tickets_sold - 1â for the product. So the value exists in the database but itâs not rendering on front-end.
As mentioned, coming from another builder (where I can do this instantly) I am struggling a little here.
Ok, not sure if I understand. Did you manage to make it work or not? If not, could you please describe your setup, especially the elements structure and where are you trying to use this custom field? Your original post was more about function not working despite being put in functions.php. So I just want to know what I can help you with precisely
The code isnât throwing the error in functions.php as per my original post - so thatâs working and creating the custom meta value in the database.
The issue now is rendering the dynamic data for this custom meta value âpercentage_of_tickets_soldâ.
In the other page builder I use, I can enter {{dc:post:meta key=âpercentage_of_tickets_soldâ}}% to display that custom meta value for each product.
So, I must be missing something on Bricks! (First site having used X/Pro theme for 6+ years).
Ok, no problem, just wanted to make sure I understand your situation correctly. So please share screenshots of your elements structure and the settings of an element that you want to output this meta in. If I see correctly, this meta is attached to the product of type âlotteryâ so is this a WooCommerce product or a different CPT created by some plugin? Just want to make sure before I make any unnecessary assumptions.
âlotteryâ is a custom woocommerce product type created by a plug-in - correct. By the custom meta value is not created by the plug-in, thatâs why we created the code in the functions.php above.
First, you donât want to use {echo:function_name} with the function to update this meta. As âechoâ tag is used to output given function value. Your function just updates stuff, doesnât return anything explicitly.
Second, please try the following:
Add new basic text element
In the elementâs âcontentâ tab, click the dynamic content icon (the bolt) and search for your field there
If you can find it, just click it and let us know if it displays on the front-end and in what form was it added inside the content box. If not, let us know as well, and I will give you additional options to try out.
How is this meta created exactly? Is it by adding a native WordPress post custom field, with ACF (or similar) or with code?
So now letâs try something that should work for 99,9%
If you know the ID of the lottery product post youâre testing, go to the next step. If not in the same text element, manually paste this: {echo:get_the_ID()}, save and on the frontend see what the ID of the post is. Remember it.
Then change the text content to this {echo:get_post_meta( 999, 'percentage_of_tickets_sold', true )} and remember to change the 999 with the lottery youâre testing. Let me know if this outputs the metakey value.
Strange. Like I said, I currently have the exact same set-up in another builder, on a live site without any issues. The builder can pick out the meta values fine. Bricks isnât able to find this in the dynamic data list it seems.
The meta field name is âpercentage_of_tickets_soldâ and the meta value is â1â. So I am trying to get the â1â to output on the front-end see.
Yeah I know, but from what Iâve quoted it sounds like you have this field name with the â-1â at the end which could be the case if WordPress thinks that you already have this field and creates a new one with â-1â at the end not to create duplicates.
You can check all available fields for this post by using code block element and pasting there the code below. Remember to check âExecute codeâ below the code field and to reload it after pasting with Ctrl+R and then saving the builder.
Thanks for that code! I checked - meta value wasnât there. I populated another product and redid the previous steps. I now have that meta value outputting with the code: {echo:get_post_meta( 259, âpercentage_of_tickets_soldâ, true )}%
But will this only appear to use the post ID (259) value? I.e. wonât this show the same value for every product?