{"id":1463010,"date":"2018-02-24T12:10:21","date_gmt":"2018-02-24T20:10:21","guid":{"rendered":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/struggling-to-set-medium-image-size-in-new-widget\/"},"modified":"2018-02-24T12:10:21","modified_gmt":"2018-02-24T20:10:21","slug":"struggling-to-set-medium-image-size-in-new-widget","status":"closed","type":"topic","link":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/struggling-to-set-medium-image-size-in-new-widget\/","title":{"rendered":"Struggling to Set Medium Image Size in New Widget"},"content":{"rendered":"<p>Hello,<\/p>\n<p>I created a topic about this a few weeks ago and I thought I had it sorted but it does look like I do. I am currently using the following code to create a custom widget that displays recently added events:<\/p>\n<p>`class EventsListWidget_NewlyAddedEvents {<br \/>\n    protected $constraints = array(<br \/>\n        &#8216;sidebar_id&#8217;   =&gt; null,<br \/>\n        &#8216;widget_id&#8217;    =&gt; null,<br \/>\n        &#8216;widget_title&#8217; =&gt; null<br \/>\n    );<\/p>\n<pre><code>public function __construct( array $constraints = array() ) {\n    $this-&amp;gt;constraints = array_merge( $this-&amp;gt;constraints, $constraints );\n    add_filter( 'widget_display_callback', array( $this, 'setup' ), 10, 3 );\n}\n\npublic function setup( $instance, $widget, $args ) {\n    \/\/ We're interested only in the (advanced or regular) events list widgets\n    $targets = array( 'tribe-events-adv-list-widget', 'tribe-events-list-widget' );\n    if ( ! in_array( $widget-&amp;gt;id_base, $targets ) ) return $instance;\n\n    \/\/ Check for constraints\n    if ( ! $this-&amp;gt;constraints_met( $instance, $args ) ) return $instance;\n\n    \/\/ Modify behaviour\n    add_filter( 'tribe_events_list_widget_query_args', array( $this, 'order_by_latest' ) );\n    return $instance;\n}\n\nprotected function constraints_met( $instance, $args ) {\n    $fail = false;\n\n    \/\/ Should only run within a specific sidebar?\n    if ( ! is_null( $this-&amp;gt;constraints['sidebar_id'] ) &amp;amp;&amp;amp; $this-&amp;gt;constraints['sidebar_id'] !== $args['id'] )\n        $fail = true;\n\n    \/\/ Should only run in relation to a specific instance of the widget?\n    if ( ! is_null( $this-&amp;gt;constraints['widget_id'] ) &amp;amp;&amp;amp; $this-&amp;gt;constraints['widget_id'] !== $args['widget_id'] )\n        $fail = true;\n\n    \/\/ Should only run when the widget title is set to something specific?\n    if ( ! is_null( $this-&amp;gt;constraints['widget_title'] ) &amp;amp;&amp;amp; $this-&amp;gt;constraints['widget_title'] !== $instance['title'] )\n        $fail = true;\n\n    return ! $fail;\n}\n\npublic function order_by_latest( $args ) {\n    \/\/ Don't interfere in other queries\n    remove_filter( 'tribe_events_list_widget_query_args', array( $this, 'order_by_latest' ) );\n\n    \/\/ Tweak the actual orderby clause\n    add_filter( 'posts_orderby', array( $this, 'override_orderby' ), 100 );\n    return $args;\n}\n\npublic function override_orderby( $orderby_sql ) {\n    global $wpdb;\n\n    \/\/ Don't interfere in other queries\n    remove_filter( 'posts_orderby', array( $this, 'override_orderby' ), 100 );\n\n    return \"$wpdb-&amp;gt;posts.post_date DESC, $orderby_sql\";\n}\n<\/code><\/pre>\n<p>}<\/p>\n<p>\/**<br \/>\n * By itself, the following line will impact <em>all<\/em> list widgets. However it may<br \/>\n * be desirable to impact just one. To achieve this, it is possible to specify<br \/>\n * one or more constraints.<br \/>\n *<br \/>\n * Valid constraints include:<br \/>\n *<br \/>\n *     sidebar_id   (the ID of the sidebar &#8211; list widgets in other sidebars will not be affected)<br \/>\n *     widget_id    (the specific widget ID itself)<br \/>\n *     widget_title (if you don&#8217;t know how to determine the widget\/sidebar ID, you can specify the title)<br \/>\n *<br \/>\n * Example:<br \/>\n *<br \/>\n *     new EventsListWidget_NewlyAddedEvents( array(<br \/>\n *         &#8216;sidebar_id&#8217; =&gt; &#8216;sidebar-1&#8217;<br \/>\n *     ) );<br \/>\n *<br \/>\n * Or:<br \/>\n *<br \/>\n *     new EventsListWidget_NewlyAddedEvents( array(<br \/>\n *         &#8216;widget_title&#8217; =&gt; &#8216;Newly Added Events!&#8217;<br \/>\n *     ) );<br \/>\n *\/<br \/>\nnew EventsListWidget_NewlyAddedEvents( array(<br \/>\n      &#8216;widget_title&#8217; =&gt; &#8216;Recently Added Events&#8217;<br \/>\n ) );`<\/p>\n<p>It all works fine apart from the images, which are using the 150&#215;150 thumbnails instead of the medium image size like other widgets. Can you help?<\/p>\n","protected":false},"template":"","class_list":["post-1463010","topic","type-topic","status-closed","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Struggling to Set Medium Image Size in New Widget -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/struggling-to-set-medium-image-size-in-new-widget\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Struggling to Set Medium Image Size in New Widget -\" \/>\n<meta property=\"og:description\" content=\"Hello, I created a topic about this a few weeks ago and I thought I had it sorted but it does look like I do. I am currently using the following code to create a custom widget that displays recently added events: `class EventsListWidget_NewlyAddedEvents { protected $constraints = array( &#8216;sidebar_id&#8217; =&gt; null, &#8216;widget_id&#8217; =&gt; null, [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/struggling-to-set-medium-image-size-in-new-widget\/\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/struggling-to-set-medium-image-size-in-new-widget\/\",\"url\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/struggling-to-set-medium-image-size-in-new-widget\/\",\"name\":\"Struggling to Set Medium Image Size in New Widget -\",\"isPartOf\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\"},\"datePublished\":\"2018-02-24T20:10:21+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/struggling-to-set-medium-image-size-in-new-widget\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/struggling-to-set-medium-image-size-in-new-widget\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/struggling-to-set-medium-image-size-in-new-widget\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/theeventscalendar.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Topics\",\"item\":\"https:\/\/theeventscalendar.com\/support\/topics\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Calendar Products\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Events Calendar PRO\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/events-calendar-pro\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Struggling to Set Medium Image Size in New Widget\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\",\"url\":\"https:\/\/theeventscalendar.com\/support\/\",\"name\":\"\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Struggling to Set Medium Image Size in New Widget -","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/struggling-to-set-medium-image-size-in-new-widget\/","og_locale":"en_US","og_type":"article","og_title":"Struggling to Set Medium Image Size in New Widget -","og_description":"Hello, I created a topic about this a few weeks ago and I thought I had it sorted but it does look like I do. I am currently using the following code to create a custom widget that displays recently added events: `class EventsListWidget_NewlyAddedEvents { protected $constraints = array( &#8216;sidebar_id&#8217; =&gt; null, &#8216;widget_id&#8217; =&gt; null, [&hellip;]","og_url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/struggling-to-set-medium-image-size-in-new-widget\/","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/struggling-to-set-medium-image-size-in-new-widget\/","url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/struggling-to-set-medium-image-size-in-new-widget\/","name":"Struggling to Set Medium Image Size in New Widget -","isPartOf":{"@id":"https:\/\/theeventscalendar.com\/support\/#website"},"datePublished":"2018-02-24T20:10:21+00:00","breadcrumb":{"@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/struggling-to-set-medium-image-size-in-new-widget\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/theeventscalendar.com\/support\/forums\/topic\/struggling-to-set-medium-image-size-in-new-widget\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/struggling-to-set-medium-image-size-in-new-widget\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/theeventscalendar.com\/support\/"},{"@type":"ListItem","position":2,"name":"Topics","item":"https:\/\/theeventscalendar.com\/support\/topics\/"},{"@type":"ListItem","position":3,"name":"Calendar Products","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/"},{"@type":"ListItem","position":4,"name":"Events Calendar PRO","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/events-calendar-pro\/"},{"@type":"ListItem","position":5,"name":"Struggling to Set Medium Image Size in New Widget"}]},{"@type":"WebSite","@id":"https:\/\/theeventscalendar.com\/support\/#website","url":"https:\/\/theeventscalendar.com\/support\/","name":"","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1463010","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1463010\/revisions"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/media?parent=1463010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}