Support

Account

Home Forums General Issues How to filter posts by event month Reply To: How to filter posts by event month

  • Dates are stored in the format YYYYMMDD. To get only posts for a specific month, lets say July of 2015. You would need to dynamically insert the year and month into the following for whatever month you need.

    
        $args = array(
            'meta_key' => 'event_date', // name of custom field
            'orderby' => 'meta_value_num',
            'order' => 'DSC',
            'cat' => '2'
            'meta_query' => array(
                'relation' => 'AND',
                array(
                    'key' => 'event_date',
                    'value' => '20150701',
                    'compare' => '>=',
                ),
                array(
                    'key' => 'event_date',
                    'value' => '20150731',
                    'compare' => '<=',
                ),
            ),
        );