Skip Navigation

[Resolved] understanding post relationships vs custom post field

This support ticket is created 5 years, 12 months 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+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 5 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#1183565

Tell us what you are trying to do?
Understanding Post relationships vs a custom post field
Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#1183581

Nigel
Supporter

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

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

"Understanding Post relationships vs a custom post field".

Perhaps if you elaborated a little on what you are aiming to do I might be able to give you a more helpful reply.

Post relationships are used to connect posts, and these connections are stored in custom database tables created by Toolset expressly for that purpose. You might have one-to-many connections (e.g. books and chapters, one book can have many chapters) or many-to-many relationships (many artists can appear at an event, and an artist can appear at many events).

See https://toolset.com/documentation/post-relationships/ for a fuller explanation.

By "a custom post field" do you mean a "Post Reference" field?

That is effectively a uni-directional one-to-one connection, as described here: https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/using-post-reference-fields-to-display-information-from-a-related-post/

If there is something specific you want to understand, let me know.

#1183695

Hi Nigel,

thank you for your reply.

Presently we have CPT: Dogs, with Name, Breed, Vet, D.O.B etc as type fields.
We’ve also previously created CPT: Breeds with its own custom fields.

As we are stringing them up via post relationships (one-to-many), we are now thinking ‘Breed’ May no longer be required as a field for CPT: Dogs, as we can use post relationship to define the breed. But before we start stripping off the field, we just want to make sure that our thoughts are in the correct direction. Eventually we will want to define a “View” that displays for example ‘All Poodles’, we want to make sure that this can be achieved via post relationship, and that the custom field ‘Breed’ for Dog CPT can be removed.

In addition, when we first created CPT Dogs, we included ‘name’ as one of the fields, and used the field to set the post title and its permalink. But now we are thinking we could use Post Title instead, and drop the name field. we allow cred edits to all fields, and we like to find out if the URL can be dynamically changed via front end forms.

thank you for your time.

#1184067

Nigel
Supporter

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

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

can we remove the breed custom field if we use relationships to connect breeds and dogs
If you were starting from scratch then I would recommend a CPT of Dogs, and Breeds would be a taxonomy (where you expand on the information for each breed with term custom fields).

Taxonomies are how you logically categorise things into groups—which seems a good fit for breeds—and within WordPress taxonomies are optimised for filtering queries (e.g. show all dogs that are poodles or cockapoodles), although this is only really significant on larger sites. You also get ready-made archives for each breed, e.g. site.com/breed/labrador/.

However, if you have started down the road doing something similar with post relationships, you can continue with a one-to-many relationship with breed (parent) << dog (child).

In which case, yes, your breed field on the dog post type becomes redundant, and you can create Views where you add a Query Filter to show dogs where the parent is set by the page where the View is shown, for example. So if you had a poodle breed and therefore had a page about poodles at site.com/poodles/ then you could insert the View there and it would list the dog posts that were related to the poodle breed.

can the URL can be dynamically changed via front end forms
If you edit a post in the back end and change the post title, the permalink (the post URL) doesn't change. You have to manually update the permalink and re-save the post.

With front-end forms it is the same. The post slug doesn't change if you modify the title.

You would need to use the Forms API, namely the cred_save_data hook, to run some code that used wp_update_post to update the post_name field with the required post slug. If you wanted to automatically update the slug based upon changes to the title, you would use sanitize_title to generate the slug.

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://codex.wordpress.org/Function_Reference/wp_update_post
https://codex.wordpress.org/Function_Reference/sanitize_title