• Resolved smunk

    (@smunk)


    I have some custom fields on a custom post type that I want to move to a taxonomy.

    I have updated the taxonomy to have the fields needed, and have written some shortcode to move the values from the fields on the CPTs to the respective taxonomy entry. All the fields moves nicely, but I cant get attachments to get inserted on the receiving Pods.

    It is easy to get the value out of the CPT, but I am not sure how to save the value on the receiving taxonomy when the field type is file, can anyone advice?

    Thanks
    Soren

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    For reference, can you share the code you were using to do this that wasn’t working?

    Thread Starter smunk

    (@smunk)

    $user= pods( 'user', $userId );
    $person= pods( 'person', $termId );
    $field = $user->field($termName);
    wp_update_term($termId, 'person', array($termName => $field));

    Moving the data from the field $termName, from a custom (file) field on a user, to a custom (file) field on a taxonomy name “person”.
    However, this doesnt work.

    • This reply was modified 6 months, 1 week ago by smunk.
    Plugin Support Paul Clark

    (@pdclark)

    Pods ->save() method will handle the difference in data types between posts, user, and taxonomy. Relationship and file fields will be an array of IDs.

    If updating a relationship field:

    <?php
    pods( 'person', $termId )->save( [ 'term_relationship_field_name' => $array_term_ids ] );

    https://docs.pods.io/code/pods/save/

    The code shared appears to just be updating the Term Name based on ID. In that case, note that args array for wp_update_term takes slug, not term_name.

    It’s also a bit odd that $termName is being used as a variable for a key in the args for wp_update_term.

    Look again at what you are trying to update about the term — then review the names for keys and data types of the variables being stored to achieve the new desired data structure.

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