0

i have two different custom post types - authors and travel reports - i want to link the author to his / hers travel reports. how can i achieve this?

thanks.

wolfram

5
  • connect them using post meta is suitable for you? Do you have any code you started with?
    – anton
    Commented Apr 30, 2021 at 11:51
  • And what posts do you have in authors post type. If you dont store them as users, maybe is better to keep them in custom taxonomy. Then you will be able to connect travel posts with checkbox, like you connect simple post with category.
    – anton
    Commented Apr 30, 2021 at 12:01
  • thanks for your comments. i use now two plugins to solve it. advanced custom fields and custom post type ui
    – wmarx
    Commented Apr 30, 2021 at 15:38
  • Usually I use own metaboxes and fields if I don't need a lot of them. If you want to connect 2 post types without a questions from my side, it's actually easy to do wtih ACF to. In wordpress by default already exist wp_dropdown_posts, ACF has similar field type - post object, where you can select a post type and recieve posts from choosen post type in dropdown view. I guess this field saves post_id value, so later you a able to show posts by these ids. advancedcustomfields.com/resources/post-object So, what help do you need here?
    – anton
    Commented Apr 30, 2021 at 16:13
  • post meta will require a meta_query which will be very expensive and does not scale. Taxonomies can group travel reports under a term representing the author, but it isn't necessary to use either meta or terms, Antti's answer references the ideal data storage and best case scenario for performance
    – Tom J Nowell
    Commented Apr 30, 2021 at 18:52

1 Answer 1

1

WP_Post has a property post_parent by default. Usually this is used for parent-child relationship on hierarchical post types, such as pages, but nothing actually prevents you from linking two different post type posts together with it.

You'll just need a metabox on your travel report CPT, which allows you to select an author CPT post (id) as the parent. This select should have post_parent as its name so that the value gets saved to the right property.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.