Support

Account

Home Forums General Issues Update Taxonomy of posts selected by acf relation field Reply To: Update Taxonomy of posts selected by acf relation field

  • Is list the name of your taxonomy? That’s about the only thing I think will cause an issue.

    This line should be limiting your the adding of terms to only things that have the values set

    
    if( $PostList ): 
    

    The post ID passed to your function for a term would be something like “term_100” where 100 will be the id of the term. You need to extract this.

    
    $term_id = intval(str_replace('term_', $post_id));
    

    and now that I’m looking at it the order of your arguments are also wrong.

    
    $posts = get_field('downloads_listing', $post_id);
    $term_id = intval(str_replace('term_', $post_id));
    if ($posts) {
      foreach ($posts as $post) {
        // make sure "list" is the taxonomy name and not the term name
        wp_set_post_terms($post->ID, $term_id, 'list', true);
      }
    }