Skip Navigation

[Resolved] Display parent post by filtering child posts

This support ticket is created 6 years, 1 month 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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 4 replies, has 3 voices.

Last updated by kaneB 6 years ago.

Assisted by: Nigel.

Author
Posts
#630194

I have a CPT "products" that has child post "Prices". I would like to create a view to display the product posts, by filtering the data fields in "prices". This is important to achieve searching of products in the view.

EG:
Display Products that has a price below $20, and i could use parametric search to find the products i want.

I understand the use of views shortcode id=$parent but this only display the information and it does not allow searching of the data fields in products.

Thanks.

#630223

You will create a View, and query the child post type which in your case is "Price".

Add all possible custom filters you want to the View.
Keep in mind that you can only add custom searches by the current post type (child) and not by parent fields or similar.
The only filter related to parent posts that can be added is a "Filter by parent post" tree filter.

Then, in the loop, instead of current post data, you can just display the parent post data.
Whenever you insert a Field in the loop with our ShortCodes you are asked where from that data should be taken.
In your case, you will choose "The parent of the current post in another post type, set by Types relationship".

That will then allow you to show the data from the parent posts within the child posts view.

It's also elaborated here:
https://toolset.com/documentation/user-guides/displaying-fields-of-parent-pages/

#638025

Hi Beda,

This is what i have been doing, and it does not help in searching through my posts. Because we are querying the child, and displaying the parent data by using the "id=$parent" attribute, it makes the data in parent data not searchable or sortable.

For example i have product Apple, with a price (child) $2.00. With this solution, i will query $2.00 and display "apple", but i cannot search for "apple" in my search box, or to sort my posts by the product name.

Any other guidance?

#638267

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Kane

Views is a user-friendly wrapper for the built-in WP_Query class used to pull posts from the database, and the way WP_Query works you can only filter by properties of the thing itself being queried (either standard fields or custom fields stored in wp_postmeta).

So if you wrote a PHP query using WP_Query to get product posts, you could only filter the results by standard product post fields or product custom fields. Filtering by fields of something else—e.g. child price posts—would require custom table joins.

That's currently not possible with Views.

As you probably know enhanced post relationships will be added in the new plugin versions due later this month when Types 3.0 is published.

The ability to filter by related posts will be included in the initial release. The ability to filter by custom fields of related posts will be added fairly soon afterwards.

So, in sum, it is currently only possible by writing custom code, but will be added within Views in the fairly-near future.

#658100

Oh well that's what i thought too, looking forward to the toolset 3.0 that could solve much of this cross relationship querying.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.