Skip Navigation

[Gelöst] 'Simplification' is 'optimization' or not?

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 Antworten, has 2 Stimmen.

Last updated by Ljuba vor 3 Jahre, 4 Monate.

Assigned support staff: Nigel.

Author
Artikel
#1104697

>>>Tell us what you are trying to do?

Several post types have essentially same fields, but namely different. Most simple example is 'Address' (but same is for Name, Phone, Email, ....). So, 'business owner' have 'Negocios' parent CPT with (ie, just for example) two 'child posts' - Hotel (Accommodation child CPT) and Restaurant (Gastronomy child CPT). ALL THREE (3) posts contain address (as field) and (imagine both options) ALL 3 ARE DIFFERENT (so, imagine, also other combinations).

'Normal' Toolset settings (looks for me) should be that I should to have 3 different address fields, but as they don't appear in same posts, they obviously could to use (technically) SAME FIELD (just should to be named different in Views and CRED outputs).

QUESTIONS

1) Is it justified to get 3 different fields and to 'save' on Views and CRED, or to get ONE FIELD and to 'make up' the Views and CRED?

P.S. - I know how question looks with 'obvious' answer, but it is not so simple. Here is about the lot of the conditionals (in Views and CRED) what not make it simple if fields are the same, as Toolset conditional DISPLAY ALL FIELDS (related or not to present post - what is logical consequence of available relationships). I also know that answer will be 'depends on situation', but my question is of 'general principle'. So, is it 'generally' optimization to get one field for 3 CPT or not (if I have 300 fields for project - 50 fields less makes difference or not? - to try to 'place question in context' - as 50 fields less makes also much more 'cosmetics' as well, as there is much more relationships)?

#1105459

Nigel
Supporter

Languages: Englisch (English ) Spanisch (Español )

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

It doesn't really make any difference, except to your mental well-being.

Custom fields are saved in wp_postmeta alongside the id of the post the custom field belongs to.

If you have just one address field wpcf-address then when you save the address on a business post the field "belongs" to the business post, and when you save the 'same' address field on a restaurant post the field belongs to the restaurant post.

The context of the post determines whether it is "a business address", "a hotel address", or "a restaurant address".

If you create a Form to publish a business, there is no ambiguity about which post the address field refers to.

If you create a View to display businesses and output the address field in the Loop Output section, there is no ambiguity about which post type the address is coming from.

You can even create a View to display a mix of businesses, hotels, and restaurants, which outputs wpcf-address, and it will still output the correct field because although the loop might be outputting any one of businesses, hotels, or restaurants, it can only be outputting one post at any one time, and that post will unambiguously be a business, or a hotel, or a restaurant.

If you are outputting fields from a related post, again, the related post could in principle be a business, or a hotel, or a restaurant, but it can only be one of those, and so there is no confusion about which "kind" of address is being output.

If you use a conditional shortcode to test whether a post has an address, it is only testing one post at a time, and that post will know which address belongs to it.

So I would tend towards using a single address field, but for you I would say do whatever you are more comfortable with.

#1105622

Thanks for clear explanations.