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

  • in general by using this code:

    
    function Taxonomy_List_Save( $post_id ) {
    		
    
    	$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);
    	  }
    	}
    
    }
    
    add_action('acf/save_post', 'Taxonomy_List_Save', 15);

    in my functions.php i should be able to edit a taxonomy term (like tags) and select a post from “RelationField” of acf and by saving the tag term page the selected post should have that tag attached automatically ?
    cause this is what i’m looking for and neither by term id or slug i can’t make it work with the above code.