Hi.
I've trying to create a view similar to the real estate theme but with a difference.
I have a parent post (Developments) with Child posts (Styles)
I'm trying to create a view to be show on the Style page to show all the other styles (brothers) within that Development (Parent)
Having created the main view, I've set the 'Content Selection on Post Type: Style and set a Query Filter to Post parent filer: Parent is the current post in the loop.
I then created a content template as follows: [wpv-view name="related-styles"]
And then created another content template: [wpv-post-body id="$parent" view_template="related-styles-in-style-page"]
I get zero results back.
If I set the post parent filter to No parent, it will return every post in Styles.
I'm confused as I've replicated something I've made on another site that works okay.
Also, is there a better way of doing this other than creating one View and 2 Content Templates? Seems a bit silly.
Filter to Post parent filer: Parent is the current post in the loop.
The Post Parent filter is only intended for use within a single hierarchical post type, like native WordPress Pages. It doesn't apply to parent / child relationships between different post types. You should use a Post Relationship filter instead, set to display posts that are a child of a particular parent ID, passed into the View using a shortcode attribute "wpvprchildof". See the attached screenshot for an example of this setup. This technique is called passing arguments into Views, and it allows you to use the same View on all your Style pages - the parent Development ID is variable, determined by the context of the current Style. If that sounded like a foreign language, don't worry yet.
Assuming the Development post type slug is "development", on the Style page you can determine the current Style's parent Development ID with the wpv-post-id shortcode and the $parent id operator:
[wpv-post-id id='$development']
Knowing that, you can pass that development ID into your View of Styles shortcode attribute like so:
[wpv-view name="your-styles-view-slug" wpvprchildof="[wpv-post-id id='$development']"]
Now your View's filter will show all Styles that are children of the current Style's parent Development. Make sure you check the setting "Don't include the current post in the results" so you don't see the current Style listed here as well.
More about the wpv-post-id shortcode:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-id
More about passing arguments into Views here:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/
Hi Christian.
Thank you for this. It does make sense and I followed this to the tee, however it still displays all the styles rather than just the styles that are only in this development.
Also I get a warning in the filter "This will filter out posts of the following types, because they are not hierarchical: Styles"
However Style is a child of development.
Not sure what I have done wrong here.
3 screenshots attached.
Right, as I mentioned before you don't want to use a post parent filter. Notice that just above the warning it says "Post parent filter" in the top of the filter box? This indicates a Post parent filter instead of a Post relationship filter. I would delete this post parent filter, and then add a new filter based on "Post Relationship" instead.
Ah! Sorry I obviously didn't read that correctly. I understand it now, and it works. Thanks so much.