Support Forum
Support › MB Relationships › Is there any way to import a csv to populate relationships?Resolved
Is it really the case that it is not possible to import the settings for relationships into metabox CPT's?
I have a site that uses toolset and would like to swap over to metabox for the same kind of function. I have rebuilt some of it but the one thing I cannot work out is how to import the relationships back in. Luckily it is only 400 posts so I could do it manually, but I would rather sort it out in a spreadsheet in advance and them bring them in with the corresponding Post IDs matching up for the relationships.
Going forward, is there any way to export and import them into another site or make changes in a spreadsheet in the future?
I use WP All Import but from the forum it does appear that there is no way currently to do it?
Is there a way to perhaps import the relationship to a custom field and then within metabox or a code snippet have the custom field update the relationship upon a save / update of the post?
Thanks in advance for any ideas.
Hi,
Unfortunately, the relationship uses the custom table to save the data so currently, there is no way to import relationship data to your site. I will inform the development team to explore the possibility.
Thank you for confirming and for asking for the possibility to be explored. It would be very helpful for the future.
I have run into this issue now as well. 🙂
Do you think there is a possible option to set post relationships in bulk using the api and mb_relationships_add?
I don't really know where to start so some pointers would be very much appreciated!
Any ideas Long?
Hi, I think a work around that i considered and from memory it did work was to set the relationship id via a post select, and then when the post is saved / updated the post ID from the post select is used to set the relationship that is saved in the custom table.
I was then considering using a google webscraper bot to automatically go through and click to update the CPT's one by one to update the relationship.
I suppose the caveat is that you would need to know the ID of the related post and set this in the CSV file prior to uploading, which is a bit of a manual task. But hopefully it would only have to be done once, and everything else would then be done on the new site with the relationships in the custom tables.
function update_client_equipment_relationship_from_client_post_id( $post_id ) {
{
//this was a post select field, but it could just be a text box with the ID set by the CSV upload?
$client_company_to_attach_equipment_to = get_post_meta( $post_id, 'client_company_to_attach_equipment_to', true );
//the relationship in the custom table is then updated using the value from the field, this code wording might be wrong, so you would need to check it carefully for your own use
MB_Relationships_API::add( $client_company_to_attach_equipment_to, $post_id, 'clients-and-equipment', $order_from = 1, );
}
}
add_action( 'rwmb_equipment-details_after_save_post', 'update_client_equipment_relationship_from_client_post_id' );
Thanks Mate!
If you get it working can you let me know? I might have to do this for real soon. Good luck.