Title: postmeta &amp; array
Last modified: August 21, 2016

---

# postmeta & array

 *  [billibones](https://wordpress.org/support/users/billibones/)
 * (@billibones)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/postmeta-array/)
 * Hi this is probably pretty basic but I have just hit a stumbling block …
 * I am currently storing data in the postmeta table and am trying to pull some 
   results on the status of a new subscriber.
 * The data in the postmeta table is stored as meta_key=userdata meta_value=”a:12:{
   a:12:{s:9:”firstname”;s:11:”TestContrib”;s:8:”lastname”;s:0:””;s:8:”cpcounty”;
   s:7:”Alameda”;s:7:”cpphone”;s:0:””;s:5:”ctype”;s:0:””;s:8:”caddress”;s:0:””;s:
   5:”ccity”;s:0:””;s:4:”czip”;s:0:””;s:11:”cited”;s:2:”No”;s:6:”cstage”;s:7:”welcome”;
   s:6:”cnotes”;s:0:””;s:5:”_meta”;a:5:{s:2:”ip”;s:14:”75.136.106.212″;s:8:”signupip”;
   s:14:”75.136.106.212″;s:10:”signuptime”;s:10:”1368150548″;s:9:”confirmip”;s:14:”
   75.136.106.212″;s:11:”confirmtime”;s:10:”1368150548″;}}”
 * On my page I am executing the following code:
 *     ```
       global $wpdb;
       $results = $wpdb->get_results( "SELECT $wpdb->postmeta.meta_value FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = 'userdata'" );
       $options = array();
       foreach ($results as $result) {
       $options[$result->meta_value] = ucwords( $result->meta_value );
       }
       foreach ($options as $key => $value) {
   
       // echo back the current stage the users are in line by line.
   
       echo $key."  ".$value."<hr />";
       }
       ```
   
 * This is currently pulling up and printing the entire serialized string within
   the database for each matched row of data. 1 for $key and 1 for $value they are
   the same (see below).
    a:12:{s:9:”firstname”;s:11:”TestContrib”;s:8:”lastname”;
   s:0:””;s:8:”cpcounty”;s:7:”Alameda”;s:7:”cpphone”;s:0:””;s:5:”ctype”;s:0:””;s:
   8:”caddress”;s:0:””;s:5:”ccity”;s:0:””;s:4:”czip”;s:0:””;s:11:”cited”;s:2:”No”;
   s:6:”cstage”;s:7:”welcome”;s:6:”cnotes”;s:0:””;s:5:”_meta”;a:5:{s:2:”ip”;s:14:”
   75.136.106.212″;s:8:”signupip”;s:14:”75.136.106.212″;s:10:”signuptime”;s:10:”
   1368150548″;s:9:”confirmip”;s:14:”75.136.106.212″;s:11:”confirmtime”;s:10:”1368150548″;}}
   A:12:{s:9:”firstname”;s:11:”TestContrib”;s:8:”lastname”;s:0:””;s:8:”cpcounty”;
   s:7:”Alameda”;s:7:”cpphone”;s:0:””;s:5:”ctype”;s:0:””;s:8:”caddress”;s:0:””;s:
   5:”ccity”;s:0:””;s:4:”czip”;s:0:””;s:11:”cited”;s:2:”No”;s:6:”cstage”;s:7:”welcome”;
   s:6:”cnotes”;s:0:””;s:5:”_meta”;a:5:{s:2:”ip”;s:14:”75.136.106.212″;s:8:”signupip”;
   s:14:”75.136.106.212″;s:10:”signuptime”;s:10:”1368150548″;s:9:”confirmip”;s:14:”
   75.136.106.212″;s:11:”confirmtime”;s:10:”1368150548″;}}
 * I am trying to just pull the value for ‘cstage’ for a single or each entry in
   the table or any other single value or perhaps multiple values later but I just
   cant figure this out..Thank you in advance for your assistance.

Viewing 1 replies (of 1 total)

 *  [Andrew Bartel](https://wordpress.org/support/users/andrew-bartel/)
 * (@andrew-bartel)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/postmeta-array/#post-3740414)
 * Use [unserialize()](http://php.net/manual/en/function.unserialize.php) on the
   value first.

Viewing 1 replies (of 1 total)

The topic ‘postmeta & array’ is closed to new replies.

## Tags

 * [array](https://wordpress.org/support/topic-tag/array/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Andrew Bartel](https://wordpress.org/support/users/andrew-bartel/)
 * Last activity: [13 years, 1 month ago](https://wordpress.org/support/topic/postmeta-array/#post-3740414)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
