Hi,
Can I set a query filter in a WordPress Archive view to show only posts having parents?
I wouldn't like to use the following in a result loop:
[wpv-conditional if="((NOT(empty($(_wpcf_belongs_xxx_id)))))"]
because it doesn't prevent including posts without parent in the query.
There are several solutions to this, right now, with the stable Toolset, if you have an existing relationship you can head to Toolset > Settings > Front End Content > Hidden custom fields
There is a button to the right, click on that to activate the hidden field _wpcf_belongs_xxx_id.
Now head to a View, and query Child Posts.
Then, add a Query Filter like:
Select items with the field:
_wpcf_belongs_toolset-parent_id is a string greater than 1
This will ensure that only posts with a Parent Post ID higher than 1 (pretty much granted, if a parent exists) will be displayed.
Posts with a parent lower than ID 1 (hence not existent) should not be shown anymore.
There are several different approaches, such as create parent posts view and nest a Child View in it that shows just posts belonging to the currently looped parent post.
But, in an archive, this is probably the simplest solution.
It should as well proceed to work after you migrate to the new Post Relationship which will be released soon.
It will however not work with post Types and relationships you create after the migration as Toolset will use a new API, which we will, of course, communicate to you in time.
I just mention this so you are aware that in future this will be done differently
Thank you. Problem solved.