0
votes

In wordpress i have created a choices value for custom field like below:

enter image description here

I am trying to get the choices values in magento

field_57bdd83367bb1 is my fieldkey

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;
    }   
}

in phtml:

$recentpost = Mage::helper('wordpress')->getblogmainbannerpost($bannercheckedblogpost['post_id']);
$posttype=  Mage::helper('wordpress')->getPostType2();
$posttype = explode(',',$posttype);
echo 'Post type:';print_r($posttype);   

output:

Array ( [0] => a:12:{s:3:"key";s:19:"field_57bdd83367bb1";s:5:"label";s:4:"Type";s:4:"name";s:4:"type";s:4:"type";s:6:"select";s:12:"instructions";s:0:"";s:8:"required";s:1:"0";s:7:"choices";a:7:{s:7:"Article";s:7:"article";s:9:"Blog Post";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:"Did You Know ?";s:12:"did_you_know";s:14:"Glossary A - Z";s:8:"glossary";}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;} )

How to properly format the above output so that i can get only Article, Blog Post, Artists & Makers, etc in my drop down

    <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>
1

1 Answers

1
votes

I believe the data format that you see there is a result of the serialize() unserialize() functions of PHP. So you would change return $results[0]['meta_value']; to return (unserialize($results[0]['meta_value']))->choices;