I'm having trouble figuring out how to design a view (using the old method, not the blocks method) which accomplishes the following.
My site has a custom post type for WORKSHOPS like "Basic Training" and "Advanced Training."
My site has another custom post type for EVENTS like "March 24, 2024 class" and "April 30, 2024 class".
There's a one-to-many relationship between these two post types, in that there might be several EVENTS for each type of WORKSHOP.
Now, one last detail: The WORKSHOPS post type also has a one-to-one relationship with any WordPress page. The idea here is that I might have a landing page for each type of workshop where I talk about it, post videos, etc.
My challenge is that I'm trying to design a [wpv-view name="workshop-events"] shortcode that I can place on any page. This view should show all the events -> that are related to the workshop -> that is related to the page the shortcode appears on.
I can't figure out any way to get the Query filter to respond to this.
What does work is if I add a variable to my shortcode e.g. [wpv-view name="workshop-events" workshopID="44"] however the whole point behind relating workshops to an arbitrary wordpress page is so that on the page can just have a generic wpv-view shortcode that will pay attention to the one-to-one relationship between WORKSHOPS and WP-PAGES.
Any ideas, or is this level of abstraction in the relationships problematic?
For what it's worth, here's how I solved it for the time being. Obviously, it's a bit of a hack so if there's a more elegant solution I'd like to hear about it.
What we've done is programmed our own shortcode [WORKSHOPS-FOR-THIS-PAGE] which figures out the workshop ID related to the page, and then constructs a wpv-view shortcode with the workshop ID supplied as a variable.
/* The [WORKSHOPS-FOR-THIS-PAGE] shortcode will insert the workshop event schedule on any page. If it is placed
on the unique page which is RELATED to a particular Workshop, it will only show events related to that Workshop.
This function invoke the workshop-events Toolset view, dynamically supplying the ID of the workshop related
to this page (if any).
*/
function doShowPageWorkshops() {
global $post;
$html = '';
$page_id = get_the_ID();
// Get the related "Workshop" post using the Toolset API
$related_workshop_id = toolset_get_related_post($page_id, 'workshop-page');
if ($related_workshop_id) {
// Get the title for the post with $related_workshop_id and wrap it in <h2>
$related_workshop_title = get_the_title($related_workshop_id);
$html .= "<h2>$related_workshop_title</h2>";
// Invoke the [wpv-view] shortcode with the related workshop ID
$shortcode = '[wpv-view name="workshop-events" wid="' . $related_workshop_id . '"]';
$html .= do_shortcode($shortcode);
} else {
// Invoke the [wpv-view] shortcode without any related workshop
$html .= "<h2>All Workshops</h2>";
$shortcode = '[wpv-view name="workshop-events"]';
$html .= do_shortcode($shortcode);
}
return $html;
}