Skip Navigation

[Resolved] I need help displaying child posts by category and subcategory on parent post.

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
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 community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 4 replies, has 2 voices.

Last updated by milesE 6 years, 5 months ago.

Assisted by: Beda.

Author
Posts
#582858
Product-View_a.png
Product-View_b.png
Subcategory view_a.png
Subcategory View_b.png
Category View_a.png
Category View_b.png
farm Layout.png
Screen Shot 2017-10-27 at 1.24.57 PM.png

I created two cpts. Farms (parent) and Products (child). I have a hierarchal taxonomy of product categories and subcategories. I would like to display child post (products) on parent post (Farm) by category and subcategory.

Farm Post
Category
Subcategory
Product name, Product name, etc.

I setup a scenario on this website and included screenshots.
hidden link

Thanks in advance.

#582968

The best is you attach the taxonomy Product Categories as well to farms.
Each farm should then be tagged with the parent terms of the child Product Terms.
This means if your Product Categories are like this:

Parent one
-- Child One
Parent Two
-- Child Two

and your Farm's Product is tagged with:

-- Child One
Parent Two
-- Child Two

you need to tag the parent Farm with:

Parent One
Parent Two

Then, you create a view for the taxonomy.
You will add a Query Filter for "Taxonomy is set by the page where this View is inserted"
It's Loop will display:

[wpv-taxonomy-title]

Now create another View where you query the Products Post Type and add a Query Filter for "Select posts that are children of the Post where this View is shown."
It's Loop contains:

[wpv-post-title]

Now head back to the Taxonomy View's Loop and add the above created Posts View to the Loop:

[wpv-taxonomy-title]
[wpv-view name="Products by Farm and Cat"]

Then, insert this Taxonomy View in a Farms Post

You will see a list of Categories (parent), under each a list of the products, you can add the Terms to each product by:

[wpv-post-taxonomy type="product-category" format="name"]

But this approach has many flaws. One is that it duplicates content in the output.

I suggest a complete different approach instead.

You want to group your Child Posts belonging to that Parent Post by a Taxonomy.
You cannot order a View's Output by a taxonomy in the backend.
Only Fields are supported.

That would suggest to use a Custom Field instead of a Taxonomy to group your Products.
Would that require a lot of refactoring on your site?

Then you can order the output by that field and even fall back to a native post meta data in case the field crosses values with another post.

#583622

Would you mind elaborating on that? Thanks

That would suggest to use a Custom Field instead of a Taxonomy to group your Products.
Would that require a lot of refactoring on your site?

Then you can order the output by that field and even fall back to a native post meta data in case the field crosses values with another post.

#584093

This means, if you would classify your content with Fields instead of Taxonomy as you use now.

You can add Custom Fields to the posts, in Toolset > Post Fields.

Once you have done that, you can populate those Fields for each Post.
Once done that, in a View, you can list those Posts and order them (either in the backend only or even in the front end) by that Field's value.
If 2 or more posts have the same Field value this would result in a uncontrollable sorting.
That is when you can fall back to secondary sorting, which will use native WordPress Post data (such as title or post date).

This would allow you to sort your posts by that fields' value - and then you can create a View where the output is sorted already by it.
You can then also group it (display only items with a certain value), and fall back to the native post data for the ordering.

#584908

Thanks for the help.

The forum ‘Types Community Support’ is closed to new topics and replies.

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