Can you try this. This should work. You don’t need to use construct if you call getData
in your theme files. You key need to be static value. After that you can call it like self::$key
Use like this : echo $theme->getData(get_the_ID());
inform me if code works 🙂
<?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.
*/