Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active June 9, 2022 21:43
Show Gist options
  • Save cliffordp/9f0d7cc5e86b2a721cd646d953bb1261 to your computer and use it in GitHub Desktop.
Save cliffordp/9f0d7cc5e86b2a721cd646d953bb1261 to your computer and use it in GitHub Desktop.

Revisions

  1. cliffordp revised this gist Mar 15, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion functions.php
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,8 @@
    *
    * From https://gist.github.com/cliffordp/9f0d7cc5e86b2a721cd646d953bb1261
    * Similar code for Essential Grid: https://gist.github.com/cliffordp/fbbaad70b9b8748819ac73f00260ac5e
    *
    * Same Slider Revolution code except with additional requirement to be a Featured Event from The Events Calendar: https://gist.github.com/cliffordp/30ac2152a8264ef27235b46b7d16332d
    *
    * revslider_get_posts filter is from /wp-content/plugins/revslider/includes/framework/functions-wordpress.class.php as of version 4.5.0
    *
    * Filter hook only applies to Slider Revolution > Post-Based Slider > Fetch Posts By Categories & Tags
  2. cliffordp revised this gist Mar 15, 2017. 1 changed file with 14 additions and 7 deletions.
    21 changes: 14 additions & 7 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -28,15 +28,22 @@ function revslider_post_based_require_featured_image( $query, $slider_id ) {
    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();
    }

    // do the filtering...

    // 'meta_query' is not used by Slider Revolution as of the time of this writing
    $query['meta_query'] = array(
    array(
    'key' => '_thumbnail_id',
    'compare' => 'EXISTS',
    ),

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

    $query['meta_query'] = $meta_query;

    return $query;
    }
  3. cliffordp revised this gist Feb 2, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@
    * Limit Slider Revolution's WP_Query to only include posts with featured images
    *
    * From https://gist.github.com/cliffordp/9f0d7cc5e86b2a721cd646d953bb1261
    * Similar code for Essential Grid: https://gist.github.com/cliffordp/fbbaad70b9b8748819ac73f00260ac5e
    *
    * revslider_get_posts filter is from /wp-content/plugins/revslider/includes/framework/functions-wordpress.class.php as of version 4.5.0
    *
  4. cliffordp revised this gist Feb 2, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,8 @@
    /**
    * Limit Slider Revolution's WP_Query to only include posts with featured images
    *
    * From https://gist.github.com/cliffordp/9f0d7cc5e86b2a721cd646d953bb1261
    *
    * revslider_get_posts filter is from /wp-content/plugins/revslider/includes/framework/functions-wordpress.class.php as of version 4.5.0
    *
    * Filter hook only applies to Slider Revolution > Post-Based Slider > Fetch Posts By Categories & Tags
  5. cliffordp revised this gist Jan 6, 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
    @@ -30,8 +30,8 @@ function revslider_post_based_require_featured_image( $query, $slider_id ) {
    // 'meta_query' is not used by Slider Revolution as of the time of this writing
    $query['meta_query'] = array(
    array(
    'key' => '_thumbnail_id',
    'compare' => 'EXISTS',
    'key' => '_thumbnail_id',
    'compare' => 'EXISTS',
    ),
    );

  6. cliffordp created this gist Jan 6, 2017.
    41 changes: 41 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    <?php

    /**
    * Limit Slider Revolution's WP_Query to only include posts with featured images
    *
    * revslider_get_posts filter is from /wp-content/plugins/revslider/includes/framework/functions-wordpress.class.php as of version 4.5.0
    *
    * Filter hook only applies to Slider Revolution > Post-Based Slider > Fetch Posts By Categories & Tags
    * or Slider Revolution > Post-Based Slider > Specific Posts > Specific Posts List (CSV of Post IDs)
    *
    * @return array
    */
    function revslider_post_based_require_featured_image( $query, $slider_id ) {

    /*
    * YOU MUST CHANGE THESE
    * TO YOUR OWN SLIDER REVOLUTION
    * SLIDER IDs
    * !!!
    */
    $slider_ids_to_affect = array( 2, 20, 34 ); // include IDs of sliders to affect

    // if this slider is not one to affect, do no filtering
    if ( ! in_array( $slider_id, $slider_ids_to_affect ) ) {
    return $query;
    }

    // do the filtering...

    // 'meta_query' is not used by Slider Revolution as of the time of this writing
    $query['meta_query'] = array(
    array(
    'key' => '_thumbnail_id',
    'compare' => 'EXISTS',
    ),
    );

    return $query;
    }

    add_filter( 'revslider_get_posts', 'revslider_post_based_require_featured_image', 10, 2 );