Skip Navigation

[Resolved] how to pass a variable to a view

This support ticket is created 8 years 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by patrickM-3 8 years ago.

Assisted by: Luo Yang.

Author
Posts
#380318

I have several nested views with a Cred form at the inner most level.

I need to store one of the variables from one of the outer views into one of the fields of the Cred form.

Where can I find a complete, straightforward guide for passing variables into views. I don't need to add this variable as a custom field to any of the other post types I'm dealing with. I just want to store a value from an outer view into the Cred fields in order to simplify the construction of another view.

How do I pass a variable, via shortcode, into a series of nested views and, ultimately, into a Cred field?

#380479

Dear patrick,

You can create a custom shortcode for it, for example, add below codes into your theme/functions.php:

add_shortcode('save-get-value', 'save_get_value_func');
function save_get_value_func($atts, $content){
	global $my_var;
	extract(shortcode_atts(array(
        'action' => 'save',
    ), $atts));
	$res = $my_var;
	if($action == 'save'){
		$my_var = do_shortcode($content);
		$res = '';
	}
	return $res;
}

When you need store some value (abc) into $my_var, use this in your content:
[save-get-value]abc[/save-get-value]

When you need to get the value from $my_var, use this in your content:
[save-get-value action="get"][/save-get-value]

#380618

Thank you, Louy. When I store a value with [save-get-value]abc[/save-get-value], is that value stored from page to page? In other words, if I set a value on one page with a view, then click a link to load a different page with a different view, can I still recall that same variable?

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