【发布时间】:2023-04-04 21:22:01
【问题描述】:
在 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:"Artists & Makers";s:16:"artistsandmakers";s:6:"Videos";s:6:"videos";s:12:"In The Press"; 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";a:3:{s:6:"status";s:1:"0";s:5:"rules";a:1:{i:0;a:2:{s: 5:"field";s:4:"null";s:8:"operator";s:2:"==";}}s:8:"allorany";s:3:"all";} 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>
【问题讨论】: