Programmatically populate an ACF relationship field on a different custom post?

[ad_1]

1. I have a “doctor” custom post type with a relationship field on it called “Specialties”. Each doctor’s selected specialties display on the doctor’s single page in the order determined by the relationship field.

2. I have a “specialties” custom post type that displays every doctor with that specialty selected in those doctors’ specialties relationship field. This is based on a query, so the doctors display in the order set by the query orderby.

3. The client only wants to relate a doctor to a specialty with a relationship field in one place (either on the doctors like it currently is, or on the specialty). They also want to be able to set a custom order for both, but fall back to the doctor query orderby if no custom order is indicated on that specialty.

4. Do you know of an easy way to accomplish this? I was thinking of creating another optional relationship field on each specialty called “Custom Order for Doctors”. Could this field be dynamically populated by the doctors with that specialty selected in the specialties relationship field on the doctor single post? I would then hide it behind a checkbox so it’s optional to set a custom order for doctors. This field would need to update when a doctor’s specialties relationship field is changed.

5. If that’s possible, could I also prevent posts from being added to or deleted from the “Custom Order for Doctors” relationship field via the GUI?

[ad_2]
1 Comment

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer