Skip Navigation

[Resolved] Archive to show only posts having parents

This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by PiotrO586 6 years, 6 months ago.

Author
Posts
#877983

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.

#878824

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

#879986

Thank you. Problem solved.