• Resolved Clicknathan

    (@clicknathan)


    I’m importing as a taxonomy term, with custom fields. CSV is like so:

    Identifier,City,County,Longitude,Latitude,
    1,"Adak, Alaska",Aleutians West,55.999722,-161.207778,

    It works, but the custom field data is then associated with a Page.

    I looked in the database, and the taxonomy term gets assigned term_id of 398.

    So I looked at Page 398, and that is where the custom field data is being stored.

    So instead of term_id 398 getting Longitude = 55.999722, the post with that ID gets the custom field.

    Any chance this could be fixed?

    Super snazzy plugin though, its even fun to use!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author smackcoders

    (@smackcoders)

    Hi @clicknathan,

    Thanks for reaching out! It sounds like you’re encountering an issue with custom fields being associated with the wrong post type. In the free version, custom fields for taxonomy terms are not supported—this feature is available in the Pro version.

    Could you please let us know which post type you’ve selected for the import? Is it posts, pages, or 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.

    Looking forward to your response!

    Thread Starter Clicknathan

    (@clicknathan)

    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:

    1. 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.
    2. 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
    3. In that example, “some custom field data” was the value of one custom field, “another custom field value” was the value of another, etc.
    4. 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.

    Plugin Author smackcoders

    (@smackcoders)

    Thanks for sharing the details and for your kind words about the plugin! We appreciate the effort you’ve put into finding a solution.

    To clarify:

    The free version doesn’t support importing custom fields into taxonomy terms, but this feature is available in the Pro version.
    We understand the current interface might be confusing, as it allows importing taxonomy terms with custom fields but attaches them to POST IDs instead of TERM IDs. We’ll address this issue in our upcoming releases to ensure custom fields are correctly associated with taxonomy terms.

    Your workaround is incredibly helpful and will benefit others facing a similar issue. Thank you for sharing.

    If you have any further questions or need additional assistance, please don’t hesitate to reach out.

    Plugin Author smackcoders

    (@smackcoders)

    Thanks again for your feedback and for sharing your workaround. Since this issue seems to be resolved, we’ll go ahead and close this topic. If you have any other questions or need help in the future, feel free to start a new topic.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.