IntelliWidget Content Driven Featured Posts and Menus

Date Features

IntelliWidget gives you the ability to filter posts by date and time. Note: The term “event” is used to describe these posts, but they can contain any type of content. To use these features, you must first enter the date and time in the Custom Fields Meta Box for each page or post you wish to filter.

IntelliWidget uses two internal date/time stamps:

  1. The Start Date is the date/time the event starts. This can also be used as the first date the post appears in the IntelliWidget section.
  2. The Expire Date is the date/time the event ends. This can also be used as the date the post should be removed from the IntelliWidget section.

There are three settings that can be used in combination to filter the content by these dates.

  1. Only future posts tells IntelliWidget to display the post only if Start Date is later than the current date. Important: The Start date must contain a value for the post to be considered a “Future” Event. Posts without a Start Date value are not displayed. The Expire Date is not used for this comparison.
  2. Exclude future posts tells IntelliWidget to display the post if the Start Date is earlier than the current date and skip the post if the Start Date is after the current date.
  3. Exclude expired posts tells IntelliWidget to hide the post if the Expire Date is earlier than the current date. In other words, an event is “expired” as soon as the Expire Date passes. The Start Date is not used for this comparison. Important: The Expire date must contain a value for the post to be considered “Expired.” Posts without Expire Dates are displayed even when this option is set.

These settings can be used together to achieve different behaviors:

  • To automatically hide posts on their Expire Date, check “Exclude expired posts.”
  • To display only posts that are going on right now, check “Exclude future posts” AND “Exclude expired posts.”
  • To display only upcoming posts, check “Only Future posts.”
  • To display current and upcoming posts, check “Exclude expired posts.” and leave the other two unchecked.

The following table illustrates the various behaviors. The check mark means the post will appear, no check mark means the post will be hidden.

Start Date Expire Date Unchecked Only Future Posts Exclude Future Posts Exclude Expired Posts Exclude Future & Expired Posts Only Future & Exclude Expired
Past Past  
Past Future    
Past -blank-  
Future Past  
Future Future  
Future -blank-  
-blank- Past  
-blank- Future    
-blank- -blank-  

Displaying Posts in an Archive Using Event Dates

WordPress does not filter or sort by Custom Data Fields by default. In order to show Upcoming events in ascending order (and not events that have already passed) you can add a “pre_get_posts” action hook to your theme’s functions.php file:


    /**
     * Show future events in ascending order
     */
    function mytheme_show_future_posts( $query ) {
        if (empty($query->query_vars['category__in']) && empty($query->query_vars['category_name'])) return;
        // this checks both category name for a match to 'event'
        if (strpos($query->query_vars['category_name'], 'event') === false):
            $is_event = false;
            // not passed as name, now check category ids
            foreach($query->query_vars['category__in'] as $cat_id):
                $cat_name = get_the_category_by_ID( $cat_id );
                if (stripos($cat_name, 'event') !== false):
                    $is_event = true;
                    break;
                endif;
            endforeach;
        else:
            $is_event = true;
        endif;
        if ($is_event):
            // adjust timestamp for locale
            $time_adj = gmdate('Y-m-d H:i', current_time('timestamp') );
            // note the orderby and order params must be in the meta_query
            // to be able to sort when using multiple meta fields
            $query->query_vars['meta_query'] = array(
                'orderby'  => 'intelliwidget_event_date',
                'order'    => 'ASC',
                'relation' => 'OR',
                array(
                    // expire date later than current time?
                    'key'     => 'intelliwidget_expire_date',
                    'value'   => $time_adj,
                    'compare' => '>'
                ),
                array(
                    // event date later than current time?
                    'key'     => 'intelliwidget_event_date',
                    'value'   => $time_adj,
                    'compare' => '>'
                ),
            );
        endif;
    }
    // add this function to the action just before running the query
    add_action( 'pre_get_posts', 'mytheme_show_future_posts' );

Need More Help? Contact Us!

Maintaining our reputation for excellent support is very important to us, so please do not hesitate to ask any question about this or any of our other plugins. You can also use the Child Theme Configurator Support Forum on WordPress.org. Don't forget to give us 5 stars!