Thanks for the response. I really do think you’ve created an awesome plugin.
Here are responses to your questions:
Could you please let us know which post type you’ve selected for the import? Is it posts, pages, or taxonomy?
Taxonomy.
Additionally, if you could share the name of the custom fields plugin you’re using, that would help us provide a more accurate solution.
I create custom fields manually via functions like add_post_meta
In the free version, custom fields for taxonomy terms are not supported—this feature is available in the Pro version.
That’s completely acceptable of course, except the plugin as is does allow you to upload taxonomy terms and use custom fields – at least the interface allows for this. But once you’ve done it, those custom fields area attached to POST ids instead of TERM ids. So it’s altering post meta in a way that is not clear, and I suspect you as the developer do not intend it to do, with your current interface.
For anyone who may come across this, the fix was:
- You have to create a taxonomy term and then, in your database — via PHPMyAdmin or something, increase the term_id to something higher than your largest current post ID. If this is daunting to you, the instructions below may not be for you.
- Then, you can import all custom field data as the term’s description. Best to separate each item by something that will never be used in one of your custom fields. For me, a comma was sufficient, but a | or ; or something might be better for your needs. I was able to use commas so that my CSV rows were like
some custom field data, another custom field value, yet another custom field value, and so on
- In that example, “some custom field data” was the value of one custom field, “another custom field value” was the value of another, etc.
- Then you can set this code up on your site to look at all of those term_descriptions and convert them to custom fields.
$terms = get_terms( array(
'taxonomy' => 'your_custom_taxonomy',
'hide_empty' => false,
) );
foreach ($terms as $term) {
$description = $term->description; // gets the term's description, where we stored our custom fields
// replace the ',' in the next line with your separator, as per my #2 point above.
// If you used a | then you'd have '|' there.
$fields_array = explode(',', $description);
// these next three lines relate to the custom field values as per my point #2 above
$some_custom_field = $fields_array[0];
$another_custom_field = $fields_array[1];
$yet_another = $fields_array[2];
// here we take our variables above and make them custom fields
update_post_meta( get_the_ID(), 'custom_field_key_1', $some_custom_field, true);
update_post_meta( get_the_ID(), 'custom_field_key_2', $another_custom_field, true);
update_post_meta( get_the_ID(), 'custom_field_key_3', $yet_another, true);
}
Always good to create a backup of your database before doing such a thing, of course.