Skip Navigation

[Resolved] Bulk assignment of relationship to existing posts

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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 6 months, 1 week ago.

Assisted by: Minesh.

Author
Posts
#2711906

I have an existing site that displays videos, with multiple post types that utilize relationships. State - County - City - Video.

Each video has been assigned to the specific city, county, and state where it took place.

I now have added a new post type for Country, and created the first post of this type, USA.

I added the states to USA manually. But there are several hundred counties, cities, and videos. Is there a way I can assign each of these to USA in bulk? I'd like to do this now, before we begin adding other Countries. 100% of all posts belong to USA right now.

This site was developed when the original Relationships structure was active, and it has never been migrated to the new style because it wasn't needed. I don't know if that would make a difference now.

Thank you for your help.

#2712378

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

There are multiple ways you can do this.

Either you can go with import plugin:
- https://toolset.com/course-lesson/how-to-import-content-into-wordpress-using-csv/

OR

You can use the post-relationship API in order to connect the child posts to parent.

For example:

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

So with above example once you replace the original values, it will connect all child posts to parent post ID 9999.

You may take this example and use some hook or shortcode to connect the many child post to your desired parent post.