I am trying to make a class in PHP that will need to use a function from WordPress, but the function doesn’t work inside the class. Is there a way to make it work? Thanks!
class MetaData
{
private $key;
public function __construct($key){
$this->key = get_post_meta($post->ID, $key, TRUE);
}
public function getData(){
print $this->key;
}
}
$postis a global variable, so you have to to explicitly state that: