Skip Navigation

[Resolved] declare a variable

This support ticket is created 6 years, 7 months 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 6 years, 7 months ago.

Assisted by: Nigel.

Author
Posts
#919643

Good afternoon I need help I would like to declare a variable example:
$ test = [types field = 'add-title' id = '$ current_page'] [/ types]

#919817

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Where are you trying to do this?

You can't use variables in HTML (e.g. in the editor for templates, posts, etc.), only in PHP or JS.

Because you have written $test as the variable, I guess you mean in PHP.

In which case you can use the do_shortcode function to parse the Types shortcode, i.e.

$test = do_shortcode( '[types field = 'add-title' id = '$current_page'] [/ types]' );

If you don't need formatted output from a Types field, you can simply use the standard get_post_meta to retrieve the raw value as stored in the database.

https://developer.wordpress.org/reference/functions/do_shortcode/
https://developer.wordpress.org/reference/functions/get_post_meta/