dongtan1009
2016-09-07 06:46
浏览 123
已采纳

如何使用PHP自定义查询从Wordpress数据库表wp_postMeta获取数据

I am developing a custom PHP based website and attaching it with WordPress database, I want to fetch data from wp_postMeta, with custom PHP not with WordPress get_post_meta.

The major issue I am facing is to convert multidimensional array and displaying record actually I don't know about that how to convert and display .

See the picture please enter image description here

图片转代码服务由CSDN问答提供 功能建议

我正在开发一个基于PHP的自定义网站并将其附加到WordPress数据库,我想从wp_postMeta获取数据, 自定义PHP不使用WordPress get_post_meta。

我面临的主要问题是转换多维数组和显示记录,实际上我不知道如何转换和显示。

请参见图片 在此输入图片说明

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douyun7718 2016-09-07 06:59
    已采纳

    So you have already the query but you can't convert this serialized array into a PHP array? Just use the PHP unserialize() function. Take a look at the PHP docs.

    unserialize() converts this:

    a:2:{i:0;s:12:"Sample array";i:1;a:2:{i:0;s:5:"Apple";i:1;s:6:"Orange";}}
    

    into this:

    Array
    (
        [0] => Sample array
        [1] => Array
            (
                [0] => Apple
                [1] => Orange
            )
    
    )
    

    In your case it could be something like this.. really easy:

    $array = unserialize( $queried_data );
    
    已采纳该答案
    打赏 评论
  • doukun0888 2016-09-07 07:02

    It is actually serialzed data.To parse this data you have to use maybe_unserialize function of wordpress and to get meta_value of a meta_key use get_post_meta('post_id','meta_key',true).This will give you meta_value of a single meta_key.In your case you can do it like this..

    $meta_value = get_post_meta('post_id','recipe_instructions',true);
    
    $array = maybe_unserialize($meta_value);
    

    Then you can get your value from array.

    打赏 评论

相关推荐 更多相似问题