Tell us what you are trying to do?
I am struggling to understand the concept of relationship fields. Where can I use them and how much freedom I have with them?
Is there any documentation that you are following?
I have read your document on post relationship that gives example of two CPTs: 1) Student and, 2) Class. You suggested using Grade as a relationship field that is common between the two. It makes sense but I am still struggling to understand the concept.
My product problem: I have two CPTs: 1) Project Prompts and, 2) Project Submissions. I want to enable people who submit "project submissions" to "rate" a "project prompt" so that other users know the quality of the "project prompt" before diving into it. Every "project prompt" can have multiple "ratings" from different users.
My question: Should I user relationship fields to capture "project prompt ratings" ? Or should I create a new post type "project prompt ratings" and show it right after a "project submission" and link it to the "parent project prompt" so that users can rate a "project prompt"?
I want to ask users a few questions as they rate a prompt so it will be like a mini NPS survey. Will relationship field option restrict me vs a "prompt rating" CPT?
Is there a third way that I am not aware of?
Hello, relationship fields are only available in a many-to-many (M2M) relationship scenario. It sounds like you want to allow multiple Users to rate a single Project Prompt post, and each "Rating" can only apply to one Project Prompt post. You did not mention any direct relationship between Ratings and Project Submissions. If my description is accurate, I don't think relationship fields are applicable here. I think you need a separate custom post type for Ratings, or a repeatable field group (RFG) inside the Prompt post type. Either could achieve what you need to capture - repeated groups of inputs, related to a single parent post. The child post type approach requires you to create a One-to-Many relationship between Ratings and Project Prompts. The RFG approach requires no extra custom post type or relationship setup.
The other main differences between the RFG approach and the child post type approach:
- Individual rows of RFGs do not get their own custom URLs on the front-end of the site, nor do they get their own editor page in wp-admin. RFGs must be edited in the parent post editor screen, and if you want to display them on the front-end of the site you would need a View.
- Child posts in a custom post type get their own custom URLs on the front-end of the site, and they get their own editor pages in wp-admin. You can also display them in Views.
On the front-end of the site, RFGs and child post types are managed similarly. Only a single instance can be created/edited in a single Form. In other words, only one "row" of an RFG, or one child post, can be created or edited in a single Form. Nested RFGs are not supported in Forms. In either case, you can allow your Users to submit a Form that generates one row of an RFG, or one child post, for a known parent Project Prompt post. Those features are possible without any need for extensive custom programming.
This sounds great, Christian. Thanks for the detailed answer.
The "project submission" post type will have a 1-1 relationship with a "rating" because I only want people who have submitted a project "via project submission" to rate a "project prompt" ONLY once.
Seems like child post is the way to go. Thank you.
My issue is resolved now. Thank you!