Skip Navigation

[Resolved] Only load a view when triggered by an acccordion button or other button

This support ticket is created 4 years, 8 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 17 replies, has 2 voices.

Last updated by Beda 4 years, 8 months ago.

Assisted by: Beda.

Author
Posts
#1547625

Hey Beda, thanks. I think I undertand the Shortcode in the View Query part. But how can I make 'myvalue' dynamic? Because since I want to make the list show different related posts (versions) based on the current project I cannot put a fixed value there, right?

So my question is: how can I pass the ID of the current post shown on the single custom post template to 'myvalue' in my php?
'myattribute' => 'dynamicvaluetakenfromcurrentproject'

#1547797

That is entirely a custom code problem.

At this point you need to define your variables in the code, pass this to the View render API, and then it will display data as related to what you pass.

Let's say you want that value to be the current post, as when you view a post.
You could access that with https://developer.wordpress.org/reference/functions/get_queried_object_id/ for example, and pass it to your variable, which then you can use to populate the render_view args.
An example:

$dynamic_view_loaded = 'Your View Title';//You can populate this however you like. You won't use this, just trying to make an example of how you could use it.
$dynamic_myattribute  = 'anotherattribute';//Again, you could go extreme, and even generate attributes on the fly, always given the view as well has some query settings for it... You won't use this, just trying to make an example of how you could use it.
$dynamic_value = 'myvalue_is_dynamic';//You can populate this with any code output you want, for example, let's say you use get_queried_object_id():
$dynamic_value = get_queried_object_id();
$args = array(
    'title' => $dynamic_view_loaded,
    $dynamic_myattribute => $dynamic_value
);
echo render_view( $args );

Depending on whether you use this on posts, or other places, like archives, you might need to use other Core API Functions or PHP Methos to get the current object ID for example, or who knows, maybe you want to load posts related to a completely different post, then you can, for example, build a Query, that gets that post, then use that Post ID to populate your render_view args.

But this is completely out of the hands of Toolset, it will depend on WordPress Query, an PHP code only.

I hope above examples help!

#1547825

PS, I forgot to mention you can also access current post data from the global $post.
This could help further to understand global $post:
https://wordpress.stackexchange.com/questions/170358/when-to-use-global-post-and-other-global-variables