Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am stuck on two issues in trying to get my custom post type for events to function correctly in the admin area.

1st) I have upgraded to wordpress 3.1 after which the code (below) which was working fine on wordpress 3.0 no longer shows any results and I can't figure out what might have messed this up. Essentially, in the code below I had the admin area sorting all posts by the event data/time.

// SET A CUSTOM SORT ORDER FOR EVENTS
   function set_event_list_admin_order($wp_query) {
    if (is_admin()) {  
        // GET THE POST TYPE FROM THE QUERY
        $todaysDate = time();
        $post_type = $wp_query->query['post_type'];  
        if ( $post_type == 'events') {
            // 'meta_key' VALUE CAN BE ANY CUSTOM FIELD  
            $wp_query->set('meta_key', '_mbcombined_datetime');
            // 'meta_compare' VALUE CAN BE ANY POST STATUS  
            $wp_query->set('meta_compare', '>=');
            // 'meta_value' VALUE CAN BE ANY POST STATUS  
            $wp_query->set('meta_value', '$todaysDate');
            // 'orderby' VALUE CAN BE ANY COLUMN NAME  
            $wp_query->set('orderby', 'meta_value');
            // 'order' VALUE CAN BE ASC or DESC  
            $wp_query->set('order', 'ASC');
            // 'post_status' VALUE CAN BE ANY POST STATUS  
            $wp_query->set('post_status', 'publish,pending,draft,future,private');
        }
    }
   }
   add_filter('pre_get_posts', 'set_event_list_admin_order');  

2nd) I have not been able to figure out what code I would need to add so that a checkbox is added above the list (by the filter by area) which let's a user check/uncheck "past events". Essentially, all I would like to do here is extend the code I have above so that by default it does not show any events where the date is older than tomorrows date. However, I do need to provide the checkbox option to "include past events" which should auto-reload the list. Any thoughts on this?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I followed this guide and I've got it working for the most part right now.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.