Skip Navigation

[Resolved] How to edit custom post type relationships in bulk (spreadsheet)

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/Karachi (GMT+05:00)

This topic contains 21 replies, has 2 voices.

Last updated by catherineB 11 months ago.

Assisted by: Waqar.

Author
Posts
#2636145

I'll try to export locations XML file through WP All Export and reimport it. I'll let you know if it works

#2636321

Hi there...
So!

I tried the XML export through WP All Export, but the _toolset_associations fields were not in the list of available fields to add in the export. I then tried to use the "migrate" option, thinking it would include the associations, but nope. The CSV was quite short and not including associations fields.

Si I tried another plugin to export in XML, and it worked, but the file was too big to be reimported

So I did a clone of the website, and deleted 2998 of the 3000 files to only keep 2. I did a regular WordPress WXR export, and reimported it in the official website. At this point, the system recognized the associations and imported the new one. The thing is that I had to manually create these associations in the clone site, they were not uploaded through CSV.

But I tried to create a CSV with the accurate _toolset_associations fields (based on an extract of the XML file), but again, the system did not recognized the imported associations.

So, if I recapitulate
- Exporting in XML with any plugins (so far): _toolset_associations fields are not included
- Exporting in CSV with any plugins (so far): _toolset_assocaitiosn fields are not included
- Exporting in WXR through the regular WP Export tool includes _toolset_association fields, but my website bug
- Importing XML files: _toolset_associations are not included
- Importing CSV files: _toolset_associations fields are not recognized
- Importing WXR files: _toolset_assocations fields are recognized and new ones are imported, but they need to be manually added to the files in the source website

- XMR files from WP tool and XML files from plugins do not have the same look / content

Is there a tool to edit XMR file in bulk?

So I'm back to the same problem, I can't edit associations in bulk (CSV file)

Right now, I have no clue about how to make it work....

#2636325
toolset-but-db-toolset-associations-3.JPG
toolset-but-db-toolset-associations-2.JPG
toolset-but-db-toolset-associations-1.JPG

Oh... and I also tried to edit the database itself with PHPmyadmin, but I could only find numbers and no way to see which CPT is related to which parent / child

I also tried to open the database with Notepad++, thinking I would actually find the same info than the XMR file, but I could again only see numbers (9, 6, 23)

This is what the XMR file includes
<wp:postmeta>
<wp:meta_key><![CDATA[_toolset_associations_lieu-et-ville]]></wp:meta_key>
<wp:meta_value><![CDATA[hidden link;
</wp:postmeta>

And the picture shows what the PHPmyadmin allows me to see (1 = the search, 2 = the databases, 3 = if I try to edit one)

#2637645

Me again, I'm thinking

Is there a shortcode that we can add to the post pages that would enable the correct relationship based on the checked taxonomy? Something we could have running at any time so the moment I refresh the post edit page, it runs and activate the relationship? (it would be shorter for me to just open each post and click on "Update", than to search and add the realtionhip(s) manually.

Ex: if (wvp-taxonomy = 'Montréal'), then (_toolset-associations-lieu-region eq 'Montréal")?

Or is that a code we could add to the CRED form, so the same process happens when I submet the form? (I could do a edit-location-form with only the taxonomies and the relationship fields (hidden)

Food for thougths 🙂

CAtherine

#2637771
toolset-associations-nor-imported-link-broken.JPG
toolset-2-of-3-associations-detected.JPG

OMG OMG !!
I found ONE one the problem....
My csv file slug title was only _toolset_associations_lieu-et-reg and NOT CF__toolset_associations_lieu-et-region

So now, I have a system that RECOGNIZE the custom fields for the associations
- cf__toolset_associations_lieu-et-quartier
- cf__toolset_associations_lieu-et-ville

But I still have issues
1) The system don't recognize cf__toolset_associations_lieu-et-region on CSV files, but it does in WXR files (I copy-pasted the slug from the WXR and added cf_ as for the 2 other associations types, so I don't understand)
2) Even if it recognize the lieu-et-quartier and lieu-et-ville slug, it imported only 3 of the 3 associations, giving me the error "3 associations couldn't be imported - Link broken associans"

I must be related to the location side of the equation, because both lieu-et-ville associations were the same (Boisbriand), and only one of the two was uploaded by Toolset

See images

#2638153

Thank you for sharing the observations. I'll try to comment on them point-by-point.

> Finally, the whole website is extremely slow (I can barely work). Did you change anything in the database? (other than the pages and views you've created). Otherwise, something happened and I don't know what!

- The only changes I made were around the created views and pages and no other website settings were changed.

> I tried exporting XML of Régions and Villes (all related to Lieux), but at each time, the only relationship recognized was the "parent" one, and nothing related to the "child" Lieu.

- Your observation is correct and expected. The relationship import mechanism through custom field works to import parent posts and intermediary posts (in case of many-to-many relationship), but not the child posts.
( ref: https://toolset.com/course-lesson/importing-content-from-csv-with-post-relationships/ )

> So, if I recapitulate
- Exporting in XML with any plugins (so far): _toolset_associations fields are not included
- Exporting in CSV with any plugins (so far): _toolset_assocaitiosn fields are not included
- Exporting in WXR through the regular WP Export tool includes _toolset_association fields, but my website bug
- Importing XML files: _toolset_associations are not included
- Importing CSV files: _toolset_associations fields are not recognized
- Importing WXR files: _toolset_assocations fields are recognized and new ones are imported, but they need to be manually added to the files in the source website
- XMR files from WP tool and XML files from plugins do not have the same look / content
Is there a tool to edit XMR file in bulk?
So I'm back to the same problem, I can't edit associations in bulk (CSV file)

- To better understand these points, it is better to understand how the relationships and their import/export work in general.

Toolset's post relationships are not stored in form of custom field values. They are stored in their dedicated tables, which I'll explain in the next point.

Because, the relationship data is not stored in the custom field values, it is also not included in the export file when you make it through any third-party export plugin.

Relationship data is included in the export file created through the regular WordPress export feature, because Toolset includes a built-in feature to include it.

But since the regular WordPress export WXR feature fails on your website's data, we'll keep the focus on the CSV export/import.

As for the relationship import feature, it looks for the custom field key/column in the specific format ( _toolset_associations_%relationship_slug% ). If some titles are found in a custom field stored in this format, it is recognized as the related post and upon the successful import of this relationship, that custom field record is deleted.

> Oh... and I also tried to edit the database itself with PHPmyadmin, but I could only find numbers and no way to see which CPT is related to which parent / child

- Information about each registered relationship can be seen in the table named '{table-prefix}_toolset_relationships'.

Whenever a post is joined in any relationship for the first time, its entry is included in the "{table-prefix}_toolset_connected_elements" table. Post ID of that post is saved under the "element_id" and every record in the table is given a new unique "id".

The actual post-relationship connections are saved in the "{table-prefix}_toolset_associations" table based on those new "ids" from the "toolset_connected_elements" table.

> But I still have issues
1) The system don't recognize cf__toolset_associations_lieu-et-region on CSV files, but it does in WXR files (I copy-pasted the slug from the WXR and added cf_ as for the 2 other associations types, so I don't understand)
2) Even if it recognize the lieu-et-quartier and lieu-et-ville slug, it imported only 3 of the 3 associations, giving me the error "3 associations couldn't be imported - Link broken associans"

- As a discussed above, for the CSV/custom field import process the expected/recognized key is "_toolset_associations_%relationship_slug%". The format 'cf__toolset_associations_%relationship_slug%' is what is used when an import/export WXR file through WordPress regular import/export feature is used.

The reason for the failed import of the recognized association would most likely be that
a). an existing parent post is already connected to the imported post
b). or previous unsuccessful import process could've incorrectly set the relevant post's relationship entry in "{table-prefix}_toolset_connected_elements" table.

Did you check the details, by clicking 'List broken associations'?
( screenshot: hidden link )

Considering what we've discussed so far, it would be best to get a custom function or shortcode developed that would:

1. Cycle through all the child posts (involved in that target relationship) in the primary language and set the existing related parent post's title in a temporary custom field key, for example '%relationship_slug%'.

Important note: When WPML translated posts are involved relationships are created only between the posts in the primary language. For the translated posts, the relationship information is inherited from the primary posts, automatically.

This way when you'll create an export CSV file through any plugin, it will be included in the exported file, as a custom field column.

2. Next, you can edit the exported CSV file to add any more titles of new connections to add for the parent posts, in that same custom field column.

3. Once the CSV file is ready, import it through any import plugin and now you'll have the new connection post titles in that custom field keys. But they won't be yet recognizable by the Toolset relationship import feature, because the key for the custom field key is not in the format "_toolset_associations_%relationship_slug%".

4. Next step would be to replace all custom field keys '%relationship_slug%' to '_toolset_associations_%relationship_slug%' format. You can either use the direct SQL search and replace operation on the database through phpMyAdmin or use custom PHP code.

5. Once the custom field key has been replaced, the associations should become available for import through the Toolset's relationship import section.

I hope these steps will make sense and let me know if any point is not clear.

#2638419

Hi Waqar,
Thanks for all your comments

It appears that I finally succeeded to make it work, partially...

Slug are working / recognized since I added the “cf_” addon a the beginning, but they work differently
a. Lieu et Quartier: I have to put the fancy name (Ville Mont-Royal)
b. Lieu et Ville: same, fancy name (La Sarre)
c. Lieu et région : slug name (abitibi-temiscamingue)

This way, I’m able to import, I would say, 70% of the associations, but still, I have some that the system really don't want to import.

When I click on the List broken associations, I get nothing. The system only restarts the scanning and bring back the usual 2 associations that stayed "stuck" in the system ahaha (from last week)

This said. I realise that not only is it really hard to convert my 3000 locations, it is also really hard to make sure all the associations are imported and valid. Plus, I can't really valide anything, as the coding in the database is only number, which are even not related to the location-post ID

That makes my job really harder than to stay with 32 different taxonomies to make my city-district segmentation 🙁

Thanks for all your help. But I won't pursue in the CPT one-to-many option

Catherine 🙂

#2639499

Thanks for all your help. But I won't pursue in the CPT one-to-many option

Catherine 🙂

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