Title: array and get post meta
Last modified: August 19, 2016

---

# array and get post meta

 *  [designrf](https://wordpress.org/support/users/designrf/)
 * (@designrf)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/array-and-get-post-meta/)
 * Hi Everybody,
 * I have a problem I try to get meta data value to put them in an php array but
   doesn’t work well.
 * I get my value called slidecolortochange but when I add it into my array the 
   size is just 1 but my array should be 2.
 * If I add directly my value into the array it works fine, i get the right size.
 * What Im doing wrong?
 *     ```
       if ( get_post_meta($post->ID, 'slidecolortochange', false) ) : ?>
   
       <?php $slidecolortochange = get_post_meta($post->ID, 'slidecolortochange', true);
   
       	$slidecolortochange = trim($slidecolortochange);
           //echo $slidecolortochange; 
   
       	$test = array($slidecolortochange);
       	print_r($test);
       	$size = count($test);
       	echo 'size : '.$size;
   
       endif; ?>
       ```
   
 * Regards

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Curtiss Grymala](https://wordpress.org/support/users/cgrymala/)
 * (@cgrymala)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/array-and-get-post-meta/#post-2016818)
 * I think the issue is that this code:
 * `<?php $slidecolortochange = get_post_meta($post->ID, 'slidecolortochange', true);`
 * should be changed to:
 * `<?php $slidecolortochange = get_post_meta($post->ID, 'slidecolortochange', false);`
 * The `true` in the first code block shown above tells WordPress to only retrieve
   a single meta value, even if multiple meta values are stored in the database.
 *  Thread Starter [designrf](https://wordpress.org/support/users/designrf/)
 * (@designrf)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/array-and-get-post-meta/#post-2017010)
 * I’ve tried before but that give me an array into another one.
 * I got that:
 *     ```
       Array
       (
           [0] => 3=>'roro', 5=>'toto'
       )
       size : 1
       ```
   
 * And my custom field value is: 3=>’roro’, 5=>’toto’
 * Maybe Im doing wrong. I just want to get a number associated with a name.
 * Do you have another idea to make it?
 *  [Curtiss Grymala](https://wordpress.org/support/users/cgrymala/)
 * (@cgrymala)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/array-and-get-post-meta/#post-2017046)
 * In that case, try:
 *     ```
       <?php $slidecolortochange = maybe_unserialize( get_post_meta($post->ID, 'slidecolortochange', true) );
       ```
   
 * and see if that works for you.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘array and get post meta’ 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/)
 * 3 replies
 * 2 participants
 * Last reply from: [Curtiss Grymala](https://wordpress.org/support/users/cgrymala/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/array-and-get-post-meta/#post-2017046)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
