Skip Navigation

[Resolved] How to get use render_view in functions.php

This support ticket is created 6 years, 2 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 6 years, 2 months ago.

Assigned support staff: Christian Cox.

Author
Posts
#545674

I am trying to: use ajax to refresh a particular view in a layout.

I can get jQuery to call a certain function in functions.php and would like to use render_view to generate the html for the view.

I am not sure what to use in the arguments to make this happen. Is there a way to pass the view-id and the post-id / parent-post-id to the call as an argument to get the right content.

Thanks
Leonard

#545698

The render_view function works in the context of the global $post object, so it's not possible to pass in an argument which will let you set the post ID or parent post ID. If you're just rendering a specific Content Template against a specific post, then the render_view_template function might be more useful for you:
https://toolset.com/documentation/programmer-reference/views-api/#render_view_template
This function can accept a View ID and a Post object. You wouldn't need to manually supply parent post information. Will this work for your needs?

Otherwise, you'll need to do some manipulation of the global $post object in order to render the View with render_view.

#545714

That sounds like it can work. I'm just not sure I understand how the global $post object works.

If jQuery from the front end kick off a function in my functions.php file would the $post object be available there to use?

Do I then just use $post as the WP_Post object that gets passed in the second argument of render_view_template?

#545743

If jQuery from the front end kick off a function in my functions.php file would the $post object be available there to use?
How exactly are you accomplishing this with jQuery? How are you exposing this function or endpoint to an AJAX request?
If you can call get_post() during this function's execution then in theory you could call get_post with this post's ID to retrieve the post object, then pass that post object in to the render_view_template call. But it really depends on how you're exposing this endpoint, and the context in which it executes.