Support

Account

Home Forums ACF PRO Save User ID as Term Meta Reply To: Save User ID as Term Meta

  • The goal is to add the user ID as term meta when a term of a custom Taxonomy is created.

    Since I’m using an ACF field for the frontend user (logged in only) to be able to add terms if needed, I thought the acf/save_post hook might be easiest. I’m just unsure of how to exactly write the code.

    I am good with editing php, if I have an example of something close to what I’m wanting… but I’ve just been coming up empty on this particular need.

    $term_id = Not sure where I'd get this from within a hook during term creation.
    
    if ($term_id is new) {
      $user_id = get_current_user_id();
      add_term_meta($term_id,$user_id,'term_author_id',true); //term would be unique, and have unique meta (unique author)
    }

    I’m not sure I’m even on the right track with my logic.

    When a post is being created or edited, if a new term has been created, that’s when I want to add the ID of the user that is doing it as term meta… so that I can later show terms made by that author back to them.

    If you could provide an example, or even the exact code you think would do it that would be AWESOME.
    Thank you!