• I’m a bit lost on how I can achieve what I need to do.

    So far I have, used php to json a public API URL, and created custom post types, and created custom taxonomy terms and used wp_set_object_terms to populate the custom taxonomy with items from an array from the API.

    My issue is that all the terms added are added unchecked. I can of course go through each custom post type post and apply the checks on the taxonomy terms i want, but i want to do this through php if possible, as i am creating many custom post type pages with data from the API.

    I’ve looked through google, but can’t find anything so far.

    I would have through that there would be a way, using php, to take the terms that have already been generated, or that are being generated from wp_set_object_terms using the array, and asking the custom post type custom taxonomy terms that are within the array to change from unchecked to checked for the custom post type post?

    • This topic was modified 6 years, 1 month ago by sonicboom81.
Viewing 3 replies - 1 through 3 (of 3 total)
  • @sonicboom81

    Can you populate the field after you insert the terms by using update?

    Like maybe,
    $yourlist = wp_get_post_terms($post->ID, ‘ ‘, array(“fields” => “ids”));
    $field_key = ‘list_your_field_here’;
    update_field($field_key, $term_list, $post->ID);

    See the saving values to post here :
    https://www.advancedcustomfields.com/resources/update_field/#usage

    Thread Starter sonicboom81

    (@sonicboom81)

    My code is using a combination of:

    
    $game_tags = array(
              $games['tags'][0]['name'],
              $games['tags'][1]['name'],
              $games['tags'][2]['name'],
              );
    
    $term_taxonomy_ids = wp_set_object_terms( $games_slug, $game_tags, 'tags_list', true );
    

    and

    
    $postID = wp_insert_post ($post_information);
    		
    update_field( 'field_5eb456a89486b', $games['name'], $inserted_game);
    update_field( 'field_5eb5c11f0f628', $games['released'], $inserted_game);
    update_field( 'field_5eb5c2d912adf', $game['background_image'], $inserted_game);
    

    To clarify what I do:

    Take values/information from an json array API using PHP and create Custom Taxonomy Terms for Custom Post Type Posts. Which works fine.

    What I can’t do:

    After running the wp_set_object_terms code and going to each Custom Post Type Post’s edit screen, the new Custom Taxonomy Terms are present, but the checkboxes which represent each Term are not checked/ not ticked.

    I want to automatically set the checkboxes to checked when i generate them using wp_set_object_terms. I don’t know if this is possible, or if my coding is wrong and it should happen automatically.

    @sonicboom81

    If the update_field function is not saving the value, then I think you should ask them in the ACF forum :
    https://support.advancedcustomfields.com/topics/

    https://support.advancedcustomfields.com/forums/search?bbp_search=update_field+save+value

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Custom Taxonomy from public API created unchecked using wp_set_object_terms’ is closed to new replies.