This thread is over two years old and may be outdated. Please create a new thread if you need help, or email us if you have an active Premium license.

Access current edited post data from within widget?

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.

Need fast email support? Get SiteOrigin Premium

Replies

2
  1. Greg Priday Staff 10 years, 4 days ago

    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. Alexandre Plennevaux 10 years, 4 days ago

    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.

Have a different question or issue?

Start New Thread