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've been asked if I can add an option for "Today" and "Yesterday" to the date filter dropdown at the top of the post list in the WordPress admin view. (This is the list that shows recent month/years.)

Date filter dropdown in post management list

Does anybody know any filter or action hook I could use to add a couple of options to this list? People have discussed adding a whole custom list here and here, but how about adding an option to one of the default lists?

share|improve this question
    
I've just realised this is a bad way to go about it, because that dropdown list corresponds to GET param "m", whereas to get Today or Yesterday I'd have to use the "day", "monthnum" and "year" params. –  And Finally Jan 29 '13 at 16:06
add comment

1 Answer

up vote 1 down vote accepted

Man, you can not hook to that filter at all. I've followed the source code in order to find out whether there is any posibility, but unfortunately, there isn't. The function which generates select months_dropdown does not contains any filter at all.

months_dropdown function is a part of a WP_List_Table class and it's derivates (Classes extending WP_List_Table). So I checked whether there is an option to replace class generating table on edit.php, and againt, there isn't. All ends up in _get_list_table function, where all acceptable classes are hardcoded, again without an option to hook in. See bellow:

function _get_list_table( $class, $args = array() ) {
    $core_classes = array(
        //Site Admin
        'WP_Posts_List_Table' => 'posts',
        'WP_Media_List_Table' => 'media',
        'WP_Terms_List_Table' => 'terms',
        'WP_Users_List_Table' => 'users',
        'WP_Comments_List_Table' => 'comments',
        'WP_Post_Comments_List_Table' => 'comments',
        'WP_Links_List_Table' => 'links',
        'WP_Plugin_Install_List_Table' => 'plugin-install',
        'WP_Themes_List_Table' => 'themes',
        'WP_Theme_Install_List_Table' => array( 'themes', 'theme-install' ),
        'WP_Plugins_List_Table' => 'plugins',
        // Network Admin
        'WP_MS_Sites_List_Table' => 'ms-sites',
        'WP_MS_Users_List_Table' => 'ms-users',
        'WP_MS_Themes_List_Table' => 'ms-themes',
    );

    if ( isset( $core_classes[ $class ] ) ) { ... } return false;

And this function is called directly from edit.php when assignig class. So you have to add another dropdown with today and yesterday options.

share|improve this answer
    
Thanks David, bad news but good to know! –  And Finally Jan 30 '13 at 10:24
    
Uh did you come across any documenation of how to add another dropdown to the filters? I can only find stuff that deals with custom taxonomies, and I just want to add a bunch of links to edit.php. –  And Finally Jan 30 '13 at 10:40
    
    
Great, thank you! –  And Finally Jan 30 '13 at 10:56
add comment

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.