Skip Navigation

[Resolved] I want to fetch a value from the DB and add it to a php-based Stylesheet

This support ticket is created 5 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 6 replies, has 2 voices.

Last updated by troyR-2 5 years, 1 month ago.

Assisted by: Waqar.

Author
Posts
#1215033
Step 2-a.jpg
Step 3-a.jpg
Step 1.jpg

Please see the illustration storyline in order from Step 1 to Step 3. If you don't understand what your seeing, then you are not the person I want answering my question. Pass it on to another tech.

Furthermore, is there a better way to do what I am attempting.

#1215106

FYI: This is all happening for development only. So, don't worry about performance issues with my "removing the cache" question in Step 3. I did solve my OPcache problem by reading this article: hidden link.

I just need to know the best way to fetch the value from the meta_value field in the wp_postmeta table. For example, whether I can do it with a Toolset shortcode, a WP shortcode or something else.

#1216730

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Troy,

Thank you for contacting us.

We apologize for the delay, as we had an unusually busy queue after the weekend.

Toolset Types plugin offers a shortcode as well as the PHP function to easily fetch the value of custom fields ( i.e. wp_postmeta table ), using the "Types Fields API":
https://toolset.com/documentation/customizing-sites-using-php/functions/

For example, your screenshot "Step 2-a.jpg" suggests that your required value is saved against the field slug "wpcf-primary-hexadecimal" with the post with ID "6527".
( screenshot: hidden link )

To get it in PHP code, you can use:


$primaryColor = types_render_field( 'primary-hexadecimal', array( 'item' => 6527) );

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1216814
500-server-error.jpg

Yes, any time I tried any of these solutions, a 500 Server error occurs. My question how do I apply the method without kicking off an error. Something is missing in your explanation because I don't see how types_render_field can stand by itself. Some code or something needs to precede it.

#1217723

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

There are more than one ways to extract data from the custom fields ( i.e. wp_postmeta table ):

1. Toolset Type's own API, that was shared in my last message.
( https://toolset.com/documentation/customizing-sites-using-php/functions/ )

And as mentioned in that documentation link, the "types_render_field" is a complete function on its own and should work, when Toolset Types plugin is active.

OR

2. WordPress own function like "get_post_meta"
( https://developer.wordpress.org/reference/functions/get_post_meta/ )

If all these methods are resulting in the same error 500, the focus should be on investigating why the server is failing to handle such requests ( hidden link ).

Unfortunately, error 500 is a very generic error and can be caused by a number of reasons, including the server's resources issues.

I would recommend checking the server's error log for more insights into this. Following articles will provide some more suggestion around investigating error 500, in a WordPress environment:

hidden link
hidden link

#1218347
solution-to-access-wordpress-2.jpg

Thank you for the advice in going to look at the error logs. The problem was All functions and shortcodes were valuing as undefined. As I said previously, something needed to precede the shortcodes/functions.

I eventually ended up accessing the database by using WordPress's get_post_meta() function. However, what was more important was gaining access to WordPress's functions by requiring the wp-load.php file located at the root of the WordPress install:

require ('../../../wp-load.php');

Now, I can use all the WordPress functions available.

To access your shortcodes, I feel I would need a similar solution. But, for now, this works for my purposes.

#1218361

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.