Skip to content

Instantly share code, notes, and snippets.

@Camwyn
Forked from cliffordp/functions.php
Last active June 10, 2022 20:48
Show Gist options
  • Save Camwyn/15e1936639a5ea7b1575b35f252ebd40 to your computer and use it in GitHub Desktop.
Save Camwyn/15e1936639a5ea7b1575b35f252ebd40 to your computer and use it in GitHub Desktop.

Revisions

  1. Camwyn revised this gist Jun 10, 2022. 1 changed file with 7 additions and 12 deletions.
    19 changes: 7 additions & 12 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -18,12 +18,7 @@
    */
    function essgrid_post_based_featured_events_w_featured_image( $query, $grid_id ) {

    /*
    * YOU MUST CHANGE THESE
    * TO YOUR OWN ESSENTIAL GRID
    * GRID IDs
    * !!!
    */
    /* YOU MUST CHANGE THESE TO YOUR OWN SLIDER REVOLUTION SLIDER IDs!!! */
    $grid_ids_to_affect = array( 1, 2, 14 ); // include IDs of grids to affect

    // if this grid is not one to affect, do no filtering
    @@ -35,27 +30,27 @@ function essgrid_post_based_featured_events_w_featured_image( $query, $grid_id )
    if ( ! empty( $query['meta_query'] ) ) {
    $meta_query = (array) $query[ 'meta_query' ];
    } else {
    $meta_query = array();
    $meta_query = [];
    }

    // do the filtering...

    // has a Featured Image
    $meta_query[] = array(
    'compare' => 'BETWEEN',
    'key' => '_thumbnail_id',
    'value' => [ 1, PHP_INT_MAX ],
    'compare' => 'BETWEEN',
    );

    // is a Featured Event (requires The Events Calendar version 4.4+ from January 9, 2017)
    // Restrict to events(posts) that have are featured events.
    if ( class_exists( 'Tribe__Events__Main' )
    && class_exists( 'Tribe__Events__Featured_Events' )
    && in_array( Tribe__Events__Main::POSTTYPE, (array) $query['post_type'] )
    ) {
    $meta_query[] = array(
    'key' => Tribe__Events__Featured_Events::FEATURED_EVENT_KEY,
    $meta_query[] = [
    'compare' => 'EXISTS',
    );
    'key' => Tribe__Events__Featured_Events::FEATURED_EVENT_KEY,
    ];
    }

    $query['meta_query'] = $meta_query;
  2. Camwyn revised this gist Jun 10, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion functions.php
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@
    *
    * essgrid_get_posts filter is from /wp-content/plugins/essential-grid/includes/base.class.php
    *
    * Tested working with version 2.1.0.2
    * Tested working with version 6.5.24
    *
    * Filter hook only applies to Essential Grid > Source > Source Based on Posts, Pages, Custom Posts
    *
  3. Camwyn revised this gist Jun 9, 2022. 1 changed file with 6 additions and 5 deletions.
    11 changes: 6 additions & 5 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -4,9 +4,9 @@
    *
    * @link https://theeventscalendar.com/knowledgebase/featured-events/
    *
    * From https://gist.github.com/cliffordp/a6aad3c60f469970b1ecb209d85ec755
    * Similar code for Slider Revolution: https://gist.github.com/cliffordp/30ac2152a8264ef27235b46b7d16332d
    * Same Essential Grid code except without requirement for being a Featured Event (works for more than just The Events Calendar): https://gist.github.com/cliffordp/fbbaad70b9b8748819ac73f00260ac5e
    * Based on https://gist.github.com/cliffordp/a6aad3c60f469970b1ecb209d85ec755
    * Similar code for Slider Revolution: https://gist.github.com/Camwyn/ce34677cafe52d46c12c11c8b9119371
    * Same Essential Grid code except without requirement for being a Featured Event (works for more than just The Events Calendar): https://gist.github.com/Camwyn/cc191bc1c95581c38f7ed5f8ba61da11
    *
    * essgrid_get_posts filter is from /wp-content/plugins/essential-grid/includes/base.class.php
    *
    @@ -43,13 +43,14 @@ function essgrid_post_based_featured_events_w_featured_image( $query, $grid_id )
    // has a Featured Image
    $meta_query[] = array(
    'key' => '_thumbnail_id',
    'compare' => 'EXISTS',
    'value' => [ 1, PHP_INT_MAX ],
    'compare' => 'BETWEEN',
    );

    // is a Featured Event (requires The Events Calendar version 4.4+ from January 9, 2017)
    if ( class_exists( 'Tribe__Events__Main' )
    && class_exists( 'Tribe__Events__Featured_Events' )
    && Tribe__Events__Main::POSTTYPE === $query['post_type']
    && in_array( Tribe__Events__Main::POSTTYPE, (array) $query['post_type'] )
    ) {
    $meta_query[] = array(
    'key' => Tribe__Events__Featured_Events::FEATURED_EVENT_KEY,
  4. @cliffordp cliffordp revised this gist Mar 15, 2017. 1 changed file with 0 additions and 7 deletions.
    7 changes: 0 additions & 7 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -38,13 +38,6 @@ function essgrid_post_based_featured_events_w_featured_image( $query, $grid_id )
    $meta_query = array();
    }

    // get the existing meta_query so we aren't wiping that out
    if ( ! empty( $query['meta_query'] ) ) {
    $meta_query = (array) $query[ 'meta_query' ];
    } else {
    $meta_query = array();
    }

    // do the filtering...

    // has a Featured Image
  5. @cliffordp cliffordp revised this gist Mar 15, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -4,9 +4,9 @@
    *
    * @link https://theeventscalendar.com/knowledgebase/featured-events/
    *
    * From https://gist.github.com/cliffordp/
    * From https://gist.github.com/cliffordp/a6aad3c60f469970b1ecb209d85ec755
    * Similar code for Slider Revolution: https://gist.github.com/cliffordp/30ac2152a8264ef27235b46b7d16332d
    * Same code except without requirement for being a Featured Event (works for more than just The Events Calendar): https://gist.github.com/cliffordp/fbbaad70b9b8748819ac73f00260ac5e
    * Same Essential Grid code except without requirement for being a Featured Event (works for more than just The Events Calendar): https://gist.github.com/cliffordp/fbbaad70b9b8748819ac73f00260ac5e
    *
    * essgrid_get_posts filter is from /wp-content/plugins/essential-grid/includes/base.class.php
    *
  6. @cliffordp cliffordp created this gist Mar 15, 2017.
    72 changes: 72 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,72 @@
    <?php
    /**
    * Limit Essential Grid's WP_Query to only include Featured Events that have a featured image
    *
    * @link https://theeventscalendar.com/knowledgebase/featured-events/
    *
    * From https://gist.github.com/cliffordp/
    * Similar code for Slider Revolution: https://gist.github.com/cliffordp/30ac2152a8264ef27235b46b7d16332d
    * Same code except without requirement for being a Featured Event (works for more than just The Events Calendar): https://gist.github.com/cliffordp/fbbaad70b9b8748819ac73f00260ac5e
    *
    * essgrid_get_posts filter is from /wp-content/plugins/essential-grid/includes/base.class.php
    *
    * Tested working with version 2.1.0.2
    *
    * Filter hook only applies to Essential Grid > Source > Source Based on Posts, Pages, Custom Posts
    *
    * @return array
    */
    function essgrid_post_based_featured_events_w_featured_image( $query, $grid_id ) {

    /*
    * YOU MUST CHANGE THESE
    * TO YOUR OWN ESSENTIAL GRID
    * GRID IDs
    * !!!
    */
    $grid_ids_to_affect = array( 1, 2, 14 ); // include IDs of grids to affect

    // if this grid is not one to affect, do no filtering
    if ( ! in_array( $grid_id, $grid_ids_to_affect ) ) {
    return $query;
    }

    // get the existing meta_query so we aren't wiping that out
    if ( ! empty( $query['meta_query'] ) ) {
    $meta_query = (array) $query[ 'meta_query' ];
    } else {
    $meta_query = array();
    }

    // get the existing meta_query so we aren't wiping that out
    if ( ! empty( $query['meta_query'] ) ) {
    $meta_query = (array) $query[ 'meta_query' ];
    } else {
    $meta_query = array();
    }

    // do the filtering...

    // has a Featured Image
    $meta_query[] = array(
    'key' => '_thumbnail_id',
    'compare' => 'EXISTS',
    );

    // is a Featured Event (requires The Events Calendar version 4.4+ from January 9, 2017)
    if ( class_exists( 'Tribe__Events__Main' )
    && class_exists( 'Tribe__Events__Featured_Events' )
    && Tribe__Events__Main::POSTTYPE === $query['post_type']
    ) {
    $meta_query[] = array(
    'key' => Tribe__Events__Featured_Events::FEATURED_EVENT_KEY,
    'compare' => 'EXISTS',
    );
    }

    $query['meta_query'] = $meta_query;

    return $query;
    }

    add_filter( 'essgrid_get_posts', 'essgrid_post_based_featured_events_w_featured_image', 10, 2 );