I am trying add custom taxonomy with post using cron job. The problem is since wordpress 4.7, it verify if current user have capability of assigning taxonomy. Crob job don't have the capability.
I am using this for registering custom taxonomoy
add_action( 'init', 'create_locations_hierarchical_taxonomy', 0 ); function create_locations_hierarchical_taxonomy() { // Add new taxonomy, make it hierarchical like categories //first do the translations part for GUI $labels = array( 'name' => _x( 'Locations', 'taxonomy general name' ), 'singular_name' => _x( 'Location', 'taxonomy singular name' ), 'search_items' => __( 'Search Locations' ), 'all_items' => __( 'All Locations' ), 'parent_item' => __( 'Parent Location' ), 'parent_item_colon' => __( 'Parent Location:' ), 'edit_item' => __( 'Edit Location' ), 'update_item' => __( 'Update Location' ), 'add_new_item' => __( 'Add New Location' ), 'new_item_name' => __( 'New Location Name' ), 'menu_name' => __( 'Locations' ), ); // Now register the taxonomy register_taxonomy('location',array('post'), array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'location' ), ));
And this script to assign taxonomy array with $post_arr
$post_location = array_map('intval', $post_location); if ($post_type == 'post') { $post_arr['tax_input'] = $post_location; }
Currently, my script can create custom taxonomy but can't assign with post..
Ref: https://core.trac.wordpress.org/browser/tags/5.1/src/wp-includes/post.php#L3784