It is reasonably simple to replace publish meta_data utilizing this:
update_post_meta( $post_id, 'standing', 'energetic');
Since I used to be really helpful to make use of customized taxonomy as an alternative, I’ve registered and created a customized taxonomy ‘standing’, by pasting the under code in my capabilities.php:
//* Add customized taxonomy 'standing' *//
perform wporg_register_taxonomy_status() {
$labels = array(
'identify' => _x( 'Standing', 'taxonomy common identify' ),
'singular_name' => _x( 'Standing', 'taxonomy singular identify' ),
'search_items' => __( 'Search Standing' ),
'all_items' => __( 'All Standing' ),
'parent_item' => __( 'Guardian Standing' ),
'parent_item_colon' => __( 'Guardian Standing:' ),
'edit_item' => __( 'Edit Standing' ),
'update_item' => __( 'Replace Standing' ),
'add_new_item' => __( 'Add New Standing' ),
'new_item_name' => __( 'New Standing Title' ),
'menu_name' => __( 'Standing' ),
);
$args = array(
'hierarchical' => true, // make it hierarchical (like classes)
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => [ 'slug' => 'status' ],
);
register_taxonomy( 'standing', [ 'post' ], $args );
}
add_action( 'init', 'wporg_register_taxonomy_status' );
Okay, so now I’ve my customized taxonomy ‘standing’.
I’ve gone to Posts > Standing contained in the wp dashboard and created two entries named:
Lively
Inactive
each have the identical slugs.
Lively has term_id: 661
Inactive has term_id: 662
Inside my create customized publish type I’ve added this line in order that when the publish is created, it could routinely set the taxonomy to ‘energetic’:
<enter sort="hidden" identify="usp-taxonomy-status[]" worth="661" />
So now I’ve all new posts with chosen standing taxonomy to ‘energetic’.
My query is learn how to use update_term_meta()
to replace my choice?
Or ought to I exploit wp_set_post_terms ();
?
In a nutshell I need one thing like this:
update_term_meta ($post_id, 'standing', 'inactive');
//and on the identical time
uncheck the 'standing', 'energetic';
In order that just one ‘inactive’ could be left chosen.
Need assistance with that.