Skip Navigation

[Resolved] Set post relationship by author

This support ticket is created 6 years, 7 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by Rune Brynestad 6 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#571936

I have 2 custom post types. Bloggs an Bloggposts. Bloggs is parent of Bloggposts. Every author will create one single Blogg and several Bloggposts. I would like to know if it is possible to automatically set all Bloggposts created by the same author as children of the Blogg created by him.

I'm aware that CRED support the parent / child relationship that Types sets up. It's possible to create forms that set parent attributes for child posts. But in this case I want to avoid a frontend solution, because a frontend solution will cause bloggers to lose important backend functionality, like Divi builder and Google Analytics

Any idea?

Thanks in advice.

Regards
Rune

#571968

Dear Rune,

There isn't such a built-in feature that can achieve what you mentioned above:
automatically set all Bloggposts created by the same author as children of the Blogg created by him.

CRED form only works in the wordpress front-end, in your case, you want the solution within wordpress admin side, so you will need to edit each child "Bloggposts" posts, setup it's parent "Blogg" post manually.
https://toolset.com/documentation/user-guides/creating-post-type-relationships/

And Types plugin is using a custom field "_wpcf_belongs_PARENT_id " to store the parent post ID, so you can also try with some PHP codes, for example:
1) when user create/edit a child "Bloggposts" post, use wordpress built-in action hook "save_post" to trigger an PHP function,
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post

2) In this custom PHP functions do this:
a) Get the related "Blogg" post ID
https://codex.wordpress.org/Template_Tags/get_posts
https://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters

b) save it into the custom field "_wpcf_belongs_blogg_id"
https://codex.wordpress.org/Function_Reference/update_post_meta

#572961

Hi Luo

Sorry for my late reply. I'll try to do the php code. It looks manageable.

Regards
Rune

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