你能试试这个吗。这应该行得通。如果调用getData
在主题文件中。您的键必须是静态值。之后你可以这样称呼它self::$key
使用方式如下:echo $theme->getData(get_the_ID());
如果代码有效,请通知我:)
<?php
class themeSettings {
private static $key= \'themeSettings\'; // We Need to create a static value
public $id; // we nedd this for postID
public function __construct() {}
public function getData($id){
//$des = get_the_title($id); For Testing
$des = get_post_meta($id,self::$key,true);
/** All these area and If clause for testing */
if($des){
//return print_r($des); For testing
return print_r($des[\'post_description\']);
} else {
return \'Yok\';
}
}
}
$theme = new themeSettings();
/**
* Simple usage $theme->getData(get_the_ID());
* Dont add global WordPress values to classes.
*/