Skip Navigation

[Resolved] Using toolset_connect_posts function

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

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)

This topic contains 5 replies, has 2 voices.

Last updated by davidm-13 6 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1105658

Hi, I want to use:
[CODE]
toolset_connect_posts('relationship-slug', parent-post-id, child-post-id)
[/CODE]
where the parent child relationship is 1 to many. I've created a (2 column excel) list of the parent post ids each with a comma separated list of the child post ids that belong to that parent.
My coding skills are very weak and I need help to load the lists into arrays and to loop thru these arrays to establish the parent child relationships. Any help or example code snippets would be very much appreciated.

Thanks
David

#1106474
parent-with-children.JPG

Hi Christian,
I've changed the input file I want to upload and attached a screenshot of it.
The first 4 digit number in each row is the parent post id, this is followed by the post ids of its children - if any.

Thanks
David

#1106740

If you want to import relationships directly into Toolset using CSV, without using PHP, you can follow the guides we have posted here:
https://toolset.com/documentation/user-guides/how-to-import-content-into-wordpress-using-csv/
There are several plugins that can help simplify this process, and step-by-step instructions.

If you want to link posts programmatically using PHP, you can search for examples of parsing CSV in PHP using fgetcsv, like these:
https://stackoverflow.com/questions/9139202/how-to-parse-a-csv-file-using-php
http://codedevelopr.com/articles/reading-csv-files-into-php-array/
I don't know of any similar examples here on the forums, since other tools exist to facilitate this type of import. If your code skills are weak, your best bet is to use one of the tools mentioned above.

#1106907

Thanks Christian,
Looking at the 3 plugins toolset recommends to import csv files, I see the free one - CSV Importer - hasn't been updated in 3 years and does not support post relationships. Does that mean I can't use this plugin and need to pay for one of the premium plugins?

Does Toolset have any plans to add a csv importer to their api? I would have thought a lot of Toolset users would find such a utility very useful.

You say "I don't know of any similar examples here on the forums, since other tools exist to facilitate this type of import."
What other free tools can I use to update post relationships?

Thanks
David

#1107608

I see the free one - CSV Importer - hasn't been updated in 3 years and does not support post relationships. Does that mean I can't use this plugin and need to pay for one of the premium plugins?
The CSV Importer doesn't provide a way to import directly into the new relationships system, but this document discusses one way you could use a free CSV importer to import posts with post relationships stored as formatted postmeta values, then use the Toolset Import Associations tool to link those posts after the import:
https://toolset.com/documentation/user-guides/importing-content-from-csv-with-post-relationships/

Does Toolset have any plans to add a csv importer to their api?
Not that I'm aware of. Feel free to submit a new ticket using the "Suggest an Improvement" feature to cast your vote for adding a CSV import tool to the Toolset suite.

#1107792

Hi Christian,
Thanks for your help. I Googled some more and found this support thread:
https://toolset.com/forums/topic/continued-connect-multiple-child-posts-to-parent-in-one-move/

I simplified it a little 'cause I wasn't sure how to loop thru the csv file. This is what I added to functions.php

add_shortcode('ts_update_db_relationships', 'ts_update_db_relationships_func');
function ts_update_db_relationships_func($args) {
   toolset_connect_posts( 'plant-with-complaint-list', 6555, 4964 );
   toolset_connect_posts( 'plant-with-complaint-list', 6555, 5308 );
   toolset_connect_posts( 'plant-with-complaint-list', 6555, 5330 );
 
    return '';
}

And it worked! So now instead of importing a csv file I'll take the excel file and with a little vba I'll output a toolset_connect_posts line for each relationship, and run the above with all the relationships. A little primitive, but gets the job done.

Thanks
David