0

I am trying to get a specific value from wp_postmeta, I'm aware about meta_key and meta_value. Problem is Meta value stores lots of values and i want specific value.

Here's the value in the meta_value

a:7:{s:19:"social_networks_url";a:9:{s:11:"twitter_url";s:0:"";s:12:"facebook_url";s:0:"";s:11:"youtube_url";s:0:"";s:15:"google-plus_url";s:0:"";s:12:"linkedin_url";s:0:"";s:13:"instagram_url";s:0:"";s:12:"dribbble_url";s:0:"";s:10:"github_url";s:0:"";s:13:"pinterest_url";s:0:"";}s:21:"page_builder_settings";s:6:"global";s:13:"date_of_birth";s:10:"1932-10-24";s:8:"location";s:185:"California <div class="rssfeeds"><img src="http://www.speakingofbusiness.com/wp-content/uploads/2014/12/logo-rss-feed.png" width="12" /><button onclick="myFunction()">RSS</button></div>";s:2:"ad";s:185:"<a href="http://www.kqzyfj.com/click-5434584-10365698" target="_top"> <img src="http://www.tqlkg.com/image-5434584-10365698" width="120" height="60" alt="www.1and1.com" border="0"/></a>";s:3:"ad1";s:2:"Hi";s:3:"ad2";s:5:"Hello";}

Now, how do i get this specific value:

I'm using get_post_custom_values( 'banda_postmeta', $post->ID ), but it returns all the value in an array and not the specific one.

1 Answer 1

0

Try this :

$value = get_post_custom_values( 'banda_postmeta', $post->ID );    
$value = unserialize("$value");
print_r($value);
echo $value['social_networks_url']['twitter_url']; 

Your social_networks_url are blank, so try echoing these values, it will echo the value.

echo $value['page_builder_settings']."<br />";
echo $value['date_of_birth']."<br />";
echo $value['location']."<br />";

Output :

array (size=7)
      'social_networks_url' => 
        array (size=9)
          'twitter_url' => string 'wr' (length=2)
          'facebook_url' => string '' (length=0)
          'youtube_url' => string '' (length=0)
          'google-plus_url' => string '' (length=0)
          'linkedin_url' => string '' (length=0)
          'instagram_url' => string '' (length=0)
          'dribbble_url' => string '' (length=0)
          'github_url' => string '' (length=0)
          'pinterest_url' => string '' (length=0)
      'page_builder_settings' => string 'global' (length=6)
      'date_of_birth' => string '1932-10-24' (length=10)
      'location' => string 'California <div class="rssfeeds"><img src="http://www.speakingofbusiness.com/wp-content/uploads/2014/12/logo-rss-feed.png" width="12" /><button onclick="myFunction()">RSS</button></div>' (length=185)
      'ad' => string '<a href="http://www.kqzyfj.com/click-5434584-10365698" target="_top"> <img src="http://www.tqlkg.com/image-5434584-10365698" width="120" height="60" alt="www.1and1.com" border="0"/></a>' (length=185)
      'ad1' => string 'Hi' (length=2)
      'ad2' => string 'Hello' (length=5)




    wr
    global
    1932-10-24
    California www.1and1.com
    Hi
    Hello

See my Code and output :

    $str = 'a:7:{s:19:"social_networks_url";a:9:{s:11:"twitter_url";s:2:"wr";s:12:"facebook_url";s:0:"";s:11:"youtube_url";s:0:"";s:15:"google-plus_url";s:0:"";s:12:"linkedin_url";s:0:"";s:13:"instagram_url";s:0:"";s:12:"dribbble_url";s:0:"";s:10:"github_url";s:0:"";s:13:"pinterest_url";s:0:"";}s:21:"page_builder_settings";s:6:"global";s:13:"date_of_birth";s:10:"1932-10-24";s:8:"location";s:185:"California <div class="rssfeeds"><img src="http://www.speakingofbusiness.com/wp-content/uploads/2014/12/logo-rss-feed.png" width="12" /><button onclick="myFunction()">RSS</button></div>";s:2:"ad";s:185:"<a href="http://www.kqzyfj.com/click-5434584-10365698" target="_top"> <img src="http://www.tqlkg.com/image-5434584-10365698" width="120" height="60" alt="www.1and1.com" border="0"/></a>";s:3:"ad1";s:2:"Hi";s:3:"ad2";s:5:"Hello";}';
    $value = unserialize($str);

    echo $value['social_networks_url']['twitter_url']."<br />";
    echo $value['page_builder_settings']."<br />";
    echo $value['date_of_birth']."<br />";
    echo $value['location']."<br />";
    echo $value['ad']."<br />";
    echo $value['ad1']."<br />";
    echo $value['ad2']."<br />";
10
  • Sorry Bindiya, It does not output anything.. Dec 26, 2014 at 5:28
  • See my edits. you can get values like this. but currently your array values are blank, so its output nothing, Dec 26, 2014 at 5:31
  • I checked array, its not blank. Dec 26, 2014 at 5:34
  • Array ( [0] => a:7:{s:19:"social_networks_url";a:9:{s:11:"twitter_url";s:0:"";s:12:"facebook_url";s:0:"";s:11:"youtube_url";s:0:"";s:15:"google-plus_url";s:0:"";s:12:"linkedin_url";s:0:"";s:13:"instagram_url";s:0:"";s:12:"dribbble_url";s:0:"";s:10:"github_url";s:0:"";s:13:"pinterest_url";s:0:"";}s:21:"page_builder_settings";s:6:"global";s:13:"date_of_birth";s:10:"1932-10-24";s:8:"location";s:185:"California RSS ";s:2:"ad";s:185:" www.1and1.com";s:3:"ad1";s:2:"Hi";s:3:"ad2";s:5:"Hello";} ) Dec 26, 2014 at 5:37
  • Try : echo $value['page_builder_settings']; Dec 26, 2014 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.