Home>Support>Access current edited post data from within widget?

Access current edited post data from within widget?

Notice: This thread is over two years old; the information may be outdated. Please consider creating a new thread if you require free support. If you have an active SiteOrigin Premium license, you can email our premium support desk at [email protected].

Hi!

I’m working on a custom SO widget that would allow to manipulate the post thumbnail.
When using the “preview” button, nothing shows up.

Here is the code inside the widget template:

if($instance['image']['featured_image'] ){
	the_post_thumbnail();
}

I’m going to try using get_template_variables( $instance, $args ) but is there any built-in method?

Thank you!
A.

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 9 years, 4 months ago Greg Priday
    Hi, I Work Here

    That’s a very good suggestion! If you have a moment, could you make this suggestion over on our Github issue tracker. As a developer yourself, it would be useful for you to post technical bug reports and feature suggestions there.

    https://github.com/siteorigin/so-widgets-bundle/issues

  2. 9 years, 4 months ago Alexandre Plennevaux

    Actually it was quite easy to make it work, using get_template_variables(). Here is how I did it:

    In the main widget declaration file:

    function get_template_variables( $instance, $args ) {
    		if( empty( $instance ) ) return array();
    		return array(
    			'queried_object' => get_queried_object(),
    			'featured_image'=>$instance['image']['featured_image'],
    			'image_file'=>$instance['image']['image_file'],
    			'title'=>$instance['title'],
    		);
    	}
    

    and in the template file:

    setup_postdata($queried_object);
    ?><figure><? the_post_thumbnail('large');?></figure>
    // More code ..
    
    // Don't forget to release the $post
    wp_reset_postdata();
    
Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More