0

I use https://rudrastyh.com/wordpress/select2-for-metaboxes-with-ajax.html.

I want to display the name of post_data inside widget tags of posts and mainly tags column inside posts list.

I can't get the name or slug of term_id from wp_set_object_terms. update_post_meta serialize automaticaly terms inside metabox. "Foreach" work fine for frontend but not for backend and I have no error.

I tried that and other solutions whith no result:

function rudr_save_metaboxdata( $post_id, $post ) {

if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id;

// if post type is different from our selected one, do nothing
if ( $post->post_type == 'post' ) {
    if( isset( $_POST['rudr_select2_tags'] ) )
    {
        
        update_post_meta( $post_id, 'rudr_select2_tags', $_POST['rudr_select2_tags'] );
        wp_set_object_terms($post_id, $_POST['rudr_select2_tags'], 'post_tag', false) ;
        
    }
    else{
        delete_post_meta( $post_id, 'rudr_select2_tags' );
    }
return $post_id;}}

"wp_set_object_terms($post_id, $_POST['rudr_select2_tags'], 'post_tag')" display only the term_id from serialize code (a:2:{i:0;s:2:"11";i:1;s:2:"23";}. I tried some solutions without results.

0

Ok. I'm really a beginner. Here is the solution:

$tags = $_POST['rudr_select2_tags'];
            foreach ( $tags as $tag ): 
                            $terms = get_term($tag); 
                            $term = $terms->name;
                            wp_set_post_terms($post_id, $tags_asso, 'post_tag', true) ;
            endforeach;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.