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.
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.
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.
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.