Skip Navigation

[Résolu] Best way to create/import one-to-many relationship

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created Il y a 8 années et 10 mois. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 -
- - - - - - -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 réponses, has 2 voix.

Last updated by laurieL-2 Il y a 8 années et 10 mois.

Assisted by: Waqas.

Auteur
Publications
#314631

Hi.

I am starting a new site where there is a one-to-many relationship between articles and authors. I will be importing data on the articles from a spreadsheet.

Since I will be importing the data, I would like to know the best way to implement the relationship. I would prefer to set up a parent (article) and child (author) relationship, because I imagine that this will be best in the long run for searching. Also, the author has multiple fields, so I can't simply make a repeating author field in the article post type.

Q1: I have read that I can specify this field for the child when I import:

_wpcf_belongs_($parent_post_type_slug)_id

That is fine, but I wonder whether I can specify my own post id for the parent when I import the parent. Otherwise, I imagine that I can export the parent data and get the post id from there?

Q2: I would also like to confirm that I can set up a CRED form for new articles (ones that will be added manually by the client through WordPress) that will save data for the parent article and the child authors at the same time.

Thanks for any suggestion on how best to do this.

#314701

Waqas
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Please consider followings regarding your questions:

Q1: I have read that I can specify this field for the child when I import:...

Yes that's the way to import a relationship based content. But unfortunately, specifying an ID for a new post isn't possible with CSV Import plugin. Because import procedure uses WP's standard API to create a new post, which auto-generates the ID. However your idea is good, that you import Parent posts first and then export to find the created IDs. So you can use with the child CPT.

Q2: I would also like to confirm that I can set up a CRED form for new articles (ones that will be added manually by the client through WordPress) that will save data for the parent article and the child authors at the same time.

Actually, you can do 1 at a time with CRED. Like separate forms for Parent and Child CPTs. Please see https://toolset.com/documentation/user-guides/cred-forms-for-child-content/ for more information.

Please let me know if I can help you with anything related.

#314753

Thanks for your reply. So, on the issue of the CRED form, I can only set the parent id on the child's form, but I cannot edit any of the parent's fields?

But I believe that I can add extra fields to a CRED form? If I did this on the parent form, what would be the hook to get this data and create the child post with php?

Thanks.

#315108

Waqas
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Yes this is true, that CRED form is capable of dealing with one CPT at a time. And of course, you can add custom stuff to your CRED form and can handle it using CRED API Hooks.

Please see https://toolset.com/documentation/user-guides/cred-api/#csd for cred_save_data() hook, where you can add your custom code to handle the fields and do the relevant stuff.

Please let me know if I can help you with anything related.

#317877

Thanks.

Le forum ‘Types Community Support’ est fermé à de nouveaux sujets et réponses.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.