在wordpress中,我为自定义字段创建了一个选择值,如下所示:
我想在magento中获取选择值
field_57bdd83367bb1是我的字段密钥
public function getPostType2()
{
try{
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('new_db');
$query = 'SELECT meta_value FROM ' . $resource->getTableName('wp_postmeta'). ' WHERE meta_key = "field_57bdd83367bb1"';
$results = $readConnection->fetchAll($query);
return $results[0]['meta_value'];
}catch (Exception $e) {
return true;
}
}
在phtml中:
$recentpost = Mage::helper('wordpress')->getblogmainbannerpost($bannercheckedblogpost['post_id']);
$posttype= Mage::helper('wordpress')->getPostType2();
$posttype = explode(',',$posttype);
echo 'Post type:';print_r($posttype);
输出:
数组([0] => a:12:{s:3:“key”; s:19:“field_57bdd83367bb1”; s:5:“label”; s:4:“Type”; s: 4: “姓名”; S:4: “类型”; S:4: “类型”; S:6: “选择”; S:12: “指令”; S:0: “”,S:8:”必需“; s:1:”0“; s:7:”选择“; a:7:{s:7:”文章“; s:7:”文章“; s:9:”博客文章“; s :9:“blog_post”; s:16:“艺术家和制造者”; s:16:“艺术家和制造者”; s:6:“视频”; s:6:“视频”; s:12:“在新闻界“; s:12:”in_the_press“; s:14:”你知道吗?“; s:12:”did_you_know“; s:14:”词汇表A - Z“; s:8:”词汇表“;} s :13:“default_value”; s:39:“blog_post in_the_press did_you_know”; s:10:“allow_null”; s:1:“0”; s:8:“multiple”; s:1:“1”; s :17: “conditional_logic”;一个:3:{S:6: “状态”; S:1: “0”; S:5: “规则”;一个:1:{I:0;一个:2:{ S:5: “场”; S:4: “空”; S:8: “经营者”; S:2: “==”;}} S:8: “allorany”; S:3: “所有” ;} s:8:“order_no”; i:0;})
如何正确格式化上述输出,以便我只能获得文章,博客文章,艺术家和我的下拉列表中的制造商等
<div class="category-list">
<?php // echo $this->__('All Types') ?>
<select id="blogcat">
<option><?php echo $this->__('Article Type') ?></option>
<option value=""><?php echo $this->__('All Types..') ?></option>
<option value="<?php echo $posttype;?>"> </option>
</select>
</div>
答案 0 :(得分:1)
我相信您看到的数据格式是PHP serialize() unserialize()函数的结果。因此,您可以将return $results[0]['meta_value'];
更改为return (unserialize($results[0]['meta_value']))->choices;