如何从wp_postmeta获得价值?

时间:2014-12-26 作者:user3378765

我试图从中获取特定值wp_postmeta, 我知道meta_keymeta_value. 问题是元值存储了很多值,我想要特定的值。

这是meta\\u值中的值

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";}
现在,如何获取此特定值:

我正在使用get_post_custom_values( \'banda_postmeta\', $post->ID ), 但它返回数组中的所有值,而不是特定值。

1 个回复
最合适的回答,由SO网友:Bindiya Patoliya 整理而成

尝试以下操作:

$value = get_post_custom_values( \'banda_postmeta\', $post->ID );    
$value = unserialize("$value");
print_r($value);
echo $value[\'social_networks_url\'][\'twitter_url\']; 
您的social_networks_url 为空,请尝试回显这些值,它将回显该值。

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

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
查看我的代码和输出:

    $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 />";

结束

相关推荐

关于共享主机上基于WordPress的大型MySQL数据库的帮助

我的WordPress数据库中有近50000篇帖子。该网站尚未上线,我在本地计算机上有数据。我在读关于WOrdpress的https://wordpress.org/plugins/hyperdb/ 可能有用的插件。然而,我不知道如何开始。我问了一位朋友,他建议我将数据库拆分,然后使用这样的插件“与”不同的数据库进行“对话”。例如,他建议我使用一个临时数据库/表从最近添加的帖子中提取帖子。临时数据库根据用户当前位置等发布帖子。您对运行大型数据库有何建议?