1

So I'm wanting to target the thumbnail but I'm not able to find it successfully. If someone could point me in the right direction I'd really appreciate it.

var_dump(profile):
enter image description here

var_dump($thumbnail):
enter image description here

Could anyone point me in the right direction to target thumbnail?

Here is my class:

class Profile
{

    // Private variables to hold data
    private $bio;
    private $thumbnail;

    // Initialize the object's id property
    public function __construct($post)
    {
        $this->set_bio($post->post_content);
        $this->set_thumbnail($this->thumbnail);
    }

    // Create the init method that calls the registered post type and pass in a id parameter
    public static function init($id)
    {
        $post = get_post($id);
        var_dump($post);

        $thumbnail = get_the_post_thumbnail_url($id);
        var_dump($thumbnail);

        $profile = new Profile($post);

        // Call to return the profile so that `Profile::init($id)` works.
        return $profile;
    }

    public function set_bio($bio)
    {
        $this->bio = $bio;
    }

    public function get_bio()
    {
        return $this->bio;
    }

    public function set_thumbnail($thumbnail)
    {
        $this->thumbnail = $thumbnail;
    }

    public function get_thumbnail()
    {
        return $this->thumbnail;
    }
}
2

Change you constructor to this

public function __construct($post)
{
    $this->set_bio($post->post_content);
    $thumbnail = get_the_post_thumbnail_url($post->ID);
    $this->set_thumbnail($thumbnail);
}

and remove thumbnail code from init method.

| improve this answer | |
  • Works like a charm - Thanks @vitauts – SLE Jan 22 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.