Skip Navigation

[Resolved] CPT and Custom Fields Structure

This thread is resolved. Here is a description of the problem and solution.

Problem:

Filter view's result by category of current post.

Solution:

You can try these:

https://toolset.com/forums/topic/cpt-and-custom-fields-structure/#post-2082323

Relevant Documentation:

https://toolset.com/documentation/user-guides/views/filtering-views-by-taxonomy/

This support ticket is created 4 years 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by kemalS-2 4 years ago.

Assisted by: Luo Yang.

Author
Posts
#2081473

Hello,

I finished the development of my own custom theme and I also already played around with Toolset to understand its functions.

Now starts my question. I am trying to develop a financial blog/compare directory site.

I am looking to find the best solution for my website regarding performance and future proof use cases.

As a financial website, we list many different topics like "Side Hustles, Passive Income, Credit Cards, Insurance, etc..." <- these are categories of my pages" but each of these topics features custom fields like "earning potential" <- this custom field would fit only the category "Side Hustles"

So should I save the custom field directly in the CPT called "Side Hustle" or should I create a CPT called "Make Money" and save the custom field in the category Side Hustle and make a conditional output that when you edit the post of the CPT "Make Money" and select the taxonomy as category "Side Hustle" the custom fields get displayed.

My question is more based on the fact of how much would this affect performance with conditional values and fields as I also use views to filter some of my CPT entries.

One example is the Side Hustles Post that is written in a WP Standard Post named "20 Side Hustle Ideas of 2021" which features a VIEW named side-hustles where the view queries data from the CPT (EITHER Make Money OR Side Hustles) but what's the better approach to set a single CPT for every category or to save custom fields directly inside the taxonomies and make them available for the CPT by selecting a category and conditional function.

I already watched a lot of courses and so on but the question about how and where to save data for the most optimal use case has not been answered to me or I just simply cant figure it out by myself.

Creating a lot of CPTs and a lot of custom entries for every CPT results in duplicates so saving the custom fields inside of the taxonomies makes more sense to me.

#2082323
cat-filter.JPG

Hello,

I assume we are talking about this case:
Two post types:
- Posts (WP built-in post type)
- Make Money( Custom post type created with Toolset Types plugin)
One taxonomy
- Category (WP built-in taxonomy)
You are going to do these:
In the single "Make Money" post, display related Posts on taxonomy "Category"

If it is, it is possible with Toolset plugins, and it does not need other custom fields. you can try these:
1) Dashboard-> Toolset-> Taxonomies, find and edit taxonomy "Categories":
In section "Post Types to be used with this Taxonomy", enable options for both post type:
- Posts
- Make Money

2) Edit each post and each "Make Money" post, setup terms in taxonomy "Categories"

3) In the single "Make Money" post, display a "View" block:
- Query Posts
- Filter by:
Select posts with taxonomy:
Categories the same as the page where this View is shown
See my screenshot cat-filter.JPG
- In view's loop, display post information

More help:
https://toolset.com/documentation/user-guides/views/filtering-views-by-taxonomy/

Value set by the current page where this View is shown
The View is always inserted somewhere. That page where the View is inserted is responsible for setting the taxonomy term. This is good when you want the same View to return different results, according to the page it’s inserted to.

#2087223

My issue is resolved now. Thank you!