## Update_post_meta serialize term_id instead name or slug tags?

Question

I use Select2 from https://rudrastyh.com/wordpress/select2-for-metaboxes-with-ajax.html.
Select2 work fine to select and display tags for each admin post.

I want to display a list (dropdown) of more than a hundred associations in this meta box.
A post can have several associations and it’s more simple to display all name of associations to be able to select one quickly.

But when I use get_post_meta to display result in frontend : First I must add implode() function to get value from serialize of meta_value (because of array) and the value is a number (term_id) instead of word (name or slug terms). The serialize code = a:1:{i:0;s:1:"6";} should be = a:1:{i:0;s:1:"thetags";}.
If I don’t use implode() function I get this error : "Array to string conversion in "

$result = get_post_meta($post->ID,'rudr_select2_tags',true);


I can’t understand why get_post_meta well display the value (a word) in backend while the serialize code store a number (the term_id). And why WordPress with get_post_meta can’t get the same value in frontend (single.php) as backend ?

I tried to use : get_terms_by(), get_term(), foreach($tags as$tag) .
I can’t do it

0
8 months 2020-12-07T10:10:21-05:00 0 Answers 11 views 0