函数在实时服务器上不起作用,但在本地主机上一切正常

时间:2015-01-10 作者:terminator

我正在使用一个类将特征图像添加到分类术语中,遵循上的教程http://en.bainternet.info/wordpress-taxonomies-extra-fields-the-easy-way/

这是我在服务中使用的代码。php(CPT文件)

require_once("Tax-meta-class/Tax-meta-class.php");

/*
* configure taxonomy custom fields
*/
$config = array(
   \'id\' => \'demo_meta_box\',                         // meta box id, unique per meta box
   \'title\' => \'Demo Meta Box\',                      // meta box title
   \'pages\' => array(\'packages_type\'),               // taxonomy name, accept categories, post_tag and custom taxonomies
   \'context\' => \'normal\',                           // where the meta box appear: normal (default), advanced, side; optional
   \'fields\' => array(),                             // list of meta fields (can be added by field arrays)
   \'local_images\' => false,                         // Use local or hosted images (meta box images for add/remove)
   \'use_with_theme\' => false                        //change path if used with theme set to true, false for a plugin or anything else for a custom path(default false).
);
$my_meta = new Tax_Meta_Class($config);
//Image field
$my_meta->addImage(\'heading\',array(\'name\'=> \'Heading \'));
$my_meta->addImage(\'image\',array(\'name\'=> \'Image \'));


/*
* Don\'t Forget to Close up the meta box deceleration
*/
//Finish Taxonomy Extra fields Deceleration
$my_meta->Finish();
然后我用这个代码来获取图像

<?php $custom_terms= get_terms(\'packages_type\');    
              $count=1;        
              $int=1;          
              foreach($custom_terms as $term):
              $heading = get_tax_meta($term->term_id,\'heading\');
              $image = get_tax_meta($term->term_id,\'image\');                  
            ?>  
<img src="<?php echo $heading[\'url\']; ?>" alt="" class="img-responsive">
<img src="<?php echo $image[\'url\']; ?>" alt="">
在localhost上一切正常,但当我将站点移动到live server时,我无法获取图像并在图像标记下获得警告-illegal string offset \'url\' .我做错了什么

1 个回复
SO网友:Irfan

amritanshu您不添加id

$my_meta->addText(\'text_field_id\',array(\'name\'=> \'My Text \'));

\'YOUR-FIELD_ID\'
打印命令只需添加该行

$saved_data = get_tax_meta($term_id,\'YOUR-FIELD-ID\');
echo$saved\\u数据;

结束

相关推荐