Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

mysql - WP_Query | meta_query argument meta value in array serialize form

In short i want get meta values from usermeta table but the meta value is in serialize array form, these values are post ids actually, this is my working code for single meta value, i want multiple values from serialize array in meta_value

 $user_id = get_current_user_id(); 
         $key = 'classes'; 
         $single = true; 
         $user_last = get_user_meta( $user_id, $key, $single ); 
         $user_last; 


    $query_args = array(
        'posts_per_page' => $output,
        'post_status' => 'publish',
        'post_type' => 'stm-courses',
        'meta_query'    => array(
                                array(
                                    'key' => 'classes',
                                    'value' => $user_last,
                                    'compare' => 'LIKE'
                                )
                            )
    );
    print_r( $query_args ); echo "string";

the single meta value is working fine but not multiple values

the below is the output of the above query

Array ( [posts_per_page] => 3 [post_status] => publish [post_type] => stm-courses [meta_query] => Array ( [0] => Array ( [key] => classes [value] => Array ( [0] => 5033 [1] => 5034 ) [compare] => LIKE ) ) ) string

and in database the value for meta_key classes is stored something like this

a:2:{i:0;s:4:"5033";i:1;s:4:"5034";}

the values are dynamically changeable so i need something dynamic logic, Thanks in advance, pls suggest me any good idea how i do this


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...