Problem:
How to display a field from a grandparent post on a grandchild post?
Solution:
The documentation describes displaying grandparent fields in a View, but you may want to display then directly in the template for grandchild posts.
The basic steps are
- create a Content Template (not assigned to any post type) to hold the fields of the grandparent you want to display.
- imagine that the starting point for *this* template is the parent post. Use the Fields and Views button to insert the required fields, and the Post selection tab to specify that the source is the parent post from the "grandparent-parent" relationship (which, if this is the parent, will be the grandparent).
- now edit the template for the grandchild posts. Insert the Content Template you just made (again, with the Fields and Views button), and use the Post selection tab to specify that the source is the parent of the current post from the "parent-grandchild" relationship.
So, starting from our grandchild post, we insert a Content Template where we specify that the source is the parent post, so that the template "thinks" its context is the parent. So when the fields inside are told to display fields from the parent, it is the parent of the parent.
Problem:
How to output a field from a parent post when displaying posts using the Essential Grid plugin?
Solution:
To display fields from the post itself you can use Views shortcodes in this format:
[wpv-post-title id='%post_id%']
[php]
To display a field from a related post (e.g. parent) it is necessary to create a custom shortcode that uses the relationships API to query the related post, like this example for a post link:
[php]
add_shortcode( 'related_link', function( $atts ){
$pid = $atts['id'];
$related_id = toolset_get_related_post( $pid, "artist-release", "parent" );
$output = wpv_do_shortcode( "[wpv-post-link id='" . $related_id . "']");
return $output;
});
which you can then insert into a template, like so: