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
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.
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?
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.