Skip Navigation

[Resolved] Bulk Assign Child Posts to Parent Post

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a one-to-many relationship set up, and I would like to be able to bulk-select child posts and assign them to the same parent in one operation.

Solution: It's not possible from wp-admin alone, you'll have to use custom code with the PHP relationship API. Here's a code snippet you can modify to your needs:

$slug = 'your-relationship-slug';
$parent = 1234;
$children = array( 1, 2, 3, 4, 5 );
// you should not edit below this line
foreach( $children as $child ) {
  toolset_connect_posts( $slug, $parent, $child );
}

Use the Toolset Custom Code feature to run the snippet once for each parent / child grouping. See below for more details.

Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

50% of people find this useful.

This support ticket is created 5 years, 6 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 6 replies, has 2 voices.

Last updated by andrewF-6 5 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#1246770

Tell us what you are trying to do?
Bulk assign Child Posts to Parent Post in One to Many Relationship setup

I am following this:
https://toolset.com/forums/topic/bulk-assign-posts-to-parent-assign-posts-to-parent-automatically/
https://toolset.com/forums/topic/how-to-bulk-set-parent-cpt/

#1246786

As I was saying the other option is to use custom code. We offer the PHP API toolset_connect_posts, which you can use to bulk-connect posts ad hoc: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

I can provide examples of that if you'd like.

#1246795

Dear Chris,

Thanks very much! I would really appreciate examples of code snippets I could use to bulk connect say 100 child posts to a parent.

Both child and parent posts share the same category if that helps.

The relationship is one parent to many child posts...

I would need to know exactly where to place the code and how I run it... for instance would it run automatically or periodically or on command.

Thanks!

#1246819

Hi Christian,

I find a free plugin called Post Connector at hidden link and https://wordpress.org/plugins/post-connector/

This plugin does exactly what I am hoping Toolset Post Relationships would do except I do not know if in using it I would be losing some Key Toolset functionalities.

It allows the bulk selection of Child Posts or Parent Posts from within either post. I believe the pro version has yet more features.

I am going to ask them if they can list taxonomies on the bulk selection page so selection accuracy will be better.

Maybe Toolset can take a look at how they make Relationship bulk selection easier to do...

Thanks

#1247104

This plugin does exactly what I am hoping Toolset Post Relationships would do except I do not know if in using it I would be losing some Key Toolset functionalities.
Yes, all Toolset Post Relationship functionality would be lost with this 3rd-party plugin. This includes the ability to use Views post relationship filters, and the shortcode notation for accessing parent posts. You will lose a lot of functionality if you implement a 3rd-party post relationship tool, since they connect posts using a proprietary method.

Maybe Toolset can take a look at how they make Relationship bulk selection easier to do...
I encourage you to submit this suggestion in our request page here: https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
I think it's a great idea to improve bulk association of related posts. This form will put your request in front of the key decision makers.

I would really appreciate examples of code snippets I could use to bulk connect say 100 child posts to a parent.
Okay here's a code snippet. You'll need to know the parent post ID, the child post IDs, and the slug of the post relationship. You can find the slug in Toolset > Relationships. Replace your-relationship-slug with the slug of your post relationship. Replace 1234 with the numeric ID of the parent post. Replace 1, 2, 3, 4, 5 with a comma-separated list of child post IDs you wish to associate with the parent post. Then you will create a new Custom Code snippet in Toolset > Settings > Custom Code. Use the option "Run on demand", then save and close the snippet. Hover over the snippet name and click "Run now". It should create the associations automatically. Then you can modify the snippet to use a different parent ID and different child IDs and run the snippet again if necessary.

$slug = 'your-relationship-slug';
$parent = 1234;
$children = array( 1, 2, 3, 4, 5 );
// you should not edit below this line
foreach( $children as $child ) {
  toolset_connect_posts( $slug, $parent, $child );
}
#1247114

Dear Toolset,

I have been a Toolset customer for several years and have submitted my share of technical support questions. Mr. Christian Cox's response to my query should be held as a model for how to respond to a question.

He assessed the situation, helped research and elucidate what my requirements were, and honestly gave options that are workable! Even though Toolset cannot do exactly what I need in the way that I want at this time, he provided me with a workable solution as to how to achieve my objective!

I had to open two tickets to get this fine response and this second response consumed less time and actually solved my issue because Chris cared to think through the problem and offer a workable potential solution.

I am appreciative for support agents like Christian who do more than just provide links to documents that may or may not be able to help but actually take the extra time to try and help us solve our problems.

We, as customers, are only asking because we have important problems that require timely solutions for our businesses and customers.

I was so pleased with this response that I felt if Christian can take the time to help me in such a genuine and complete way, I too have a responsibility to take the time to express my appreciation and gratitude.

My Issue is resolved and I will be submitting a new feature request for Toolset as well.

Thank you Christian.

#1247117

My issue is resolved now. Thank you!