$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>php - Get user by meta data key and velue|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - Get user by meta data key and velue

matteradmin16PV0评论

I have create custom user meta, but it was array how i can call only one of them by key like I want to get only course_id = 22 list.
Here this my user meta array

 [certifications] => Array
        (
            [0] => a:9:{s:9:"course_id";a:2:{i:0;s:0:"";i:1;s:2:"19";}s:11:"course_name";a:2:{i:0;s:0:"";i:1;s:18:"Advanced Freediver";}s:6:"course";a:2:{i:0;s:0:"";i:1;s:2:"19";}s:4:"date";a:2:{i:0;s:0:"";i:1;s:10:"05/03/2019";}s:10:"instructor";a:2:{i:0;s:0:"";i:1;s:11:"Camila Amor";}s:6:"school";a:2:{i:0;s:0:"";i:1;s:24:"Apnea Total Headquarters";}s:11:"pdf_card_id";a:2:{i:0;s:0:"";i:1;s:2:"19";}s:7:"pdf_dip";a:2:{i:0;s:0:"";i:1;s:2:"19";}s:11:"last_update";s:10:"21-03-2019";}
            [1] => a:9:{s:9:"course_id";a:2:{i:0;s:0:"";i:1;s:2:"22";}s:11:"course_name";a:2:{i:0;s:0:"";i:1;s:16:"Master Freediver";}s:6:"course";a:2:{i:0;s:0:"";i:1;s:2:"22";}s:4:"date";a:2:{i:0;s:0:"";i:1;s:10:"08/03/2019";}s:10:"instructor";a:2:{i:0;s:0:"";i:1;s:14:"Andres Alegria";}s:6:"school";a:2:{i:0;s:0:"";i:1;s:17:"Vertical Dreamers";}s:11:"pdf_card_id";a:2:{i:0;s:0:"";i:1;s:2:"22";}s:7:"pdf_dip";a:2:{i:0;s:0:"";i:1;s:2:"22";}s:11:"last_update";s:10:"21-03-2019";}
        ) 

I have create custom user meta, but it was array how i can call only one of them by key like I want to get only course_id = 22 list.
Here this my user meta array

 [certifications] => Array
        (
            [0] => a:9:{s:9:"course_id";a:2:{i:0;s:0:"";i:1;s:2:"19";}s:11:"course_name";a:2:{i:0;s:0:"";i:1;s:18:"Advanced Freediver";}s:6:"course";a:2:{i:0;s:0:"";i:1;s:2:"19";}s:4:"date";a:2:{i:0;s:0:"";i:1;s:10:"05/03/2019";}s:10:"instructor";a:2:{i:0;s:0:"";i:1;s:11:"Camila Amor";}s:6:"school";a:2:{i:0;s:0:"";i:1;s:24:"Apnea Total Headquarters";}s:11:"pdf_card_id";a:2:{i:0;s:0:"";i:1;s:2:"19";}s:7:"pdf_dip";a:2:{i:0;s:0:"";i:1;s:2:"19";}s:11:"last_update";s:10:"21-03-2019";}
            [1] => a:9:{s:9:"course_id";a:2:{i:0;s:0:"";i:1;s:2:"22";}s:11:"course_name";a:2:{i:0;s:0:"";i:1;s:16:"Master Freediver";}s:6:"course";a:2:{i:0;s:0:"";i:1;s:2:"22";}s:4:"date";a:2:{i:0;s:0:"";i:1;s:10:"08/03/2019";}s:10:"instructor";a:2:{i:0;s:0:"";i:1;s:14:"Andres Alegria";}s:6:"school";a:2:{i:0;s:0:"";i:1;s:17:"Vertical Dreamers";}s:11:"pdf_card_id";a:2:{i:0;s:0:"";i:1;s:2:"22";}s:7:"pdf_dip";a:2:{i:0;s:0:"";i:1;s:2:"22";}s:11:"last_update";s:10:"21-03-2019";}
        ) 
Share Improve this question edited Mar 21, 2019 at 12:17 Qaisar Feroz 2,1471 gold badge9 silver badges20 bronze badges asked Mar 21, 2019 at 11:52 NewBleNewBle 12 bronze badges 5
  • how are you creating this meta? and why is it being stored as serialized data inside an array? – mrben522 Commented Mar 21, 2019 at 12:57
  • it is default array stored from wordpress. – NewBle Commented Mar 21, 2019 at 13:53
  • please add the code you are using to create/store that meta and what you are using to pull it out in the current format – mrben522 Commented Mar 21, 2019 at 14:15
  • This how my stored function is for this meta group $certification = array( 'course_name' => $certificate_name, 'course' => $certificate, 'date' => $date, 'instructor' => $certifying_instructor, 'school' => $school, 'last_update' => date('d-m-Y'), ); add_user_meta( $user_ids, 'certifications', $certification ); – NewBle Commented Mar 21, 2019 at 14:34
  • If you have to have them all stored in a single meta field ('certifications') then you're going to need to parse out the data in them and then pullout the array you want from there. check out maybe_unserialize() for help getting that data into a readable format – mrben522 Commented Mar 21, 2019 at 14:44
Add a comment  | 

1 Answer 1

Reset to default 0

This how my stored data function is for this meta group and get data

stored

$certification = array(
        'course_id' => $certificate_id,
        'course' => $certificate,
        'date' => $date,
        'instructor' => $certifying_instructor,
        'school' => $school,
        'last_update' => date('d-m-Y'),
    );

    add_user_meta( $user_ids, 'certifications',  $certification );

and this get data

$users_detail = get_user_meta($user_id);
$certificates = $users_detail['certifications'];

$n_course_id = array();

foreach ($certificates as $value) {
   $course = unserialize($value);
   $course_id = $course['course_id'];

   foreach ($course_id as $courses) {
     array_push($n_course_id, $courses);
   }

}

by this function i can get all list but i want to get only one of them

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far