Custom dashboard widget search box

I’d like to create a custom dashboard widget that contains the search box from the posts edit screen.

I know how to create the dashboard widget and how to display it, but I don’t know how can I place the search box.

Related posts

Leave a Reply

1 comment

  1. The following will do, although it redirects to the Posts listing page /wp-admin/edit.php

    Also included, search boxes for Pages and CPTs.

    Code

    /**
     * PLEASE NOTE THAT THE FOLLOWING CODE DOESN'T HAVE ANY SANITIZATION or NONCE methods
    */
    
    add_action('wp_dashboard_setup', 'wpse_58520_dashboard_search_widget');
    
    function wpse_58520_dashboard_search_widget() {
        wp_add_dashboard_widget( 'wpse_54742_active_site_plugins', __( 'Search Posts/Pages/CPTs' ), 'wpse_58520_make_dashboard_search_widget' );
    }
    
    function wpse_58520_make_dashboard_search_widget() {
        ?>
            <form id="posts-filter" action="/wp-admin/edit.php" method="get">
            <div class="search-box" style="height:50px">
                <input type="search" id="post-search-input" name="s" value="">
                <input type="submit" name="" id="search-submit" class="button" value="Search Posts"></p>
            </div>
            </form>
    
            <form id="pages-filter" action="/wp-admin/edit.php" method="get">
            <div class="search-box" style="height:50px">
                <input type="search" id="page-search-input" name="s" value="">
                <input type="hidden" name="post_type" value="page" /> 
                <input type="submit" name="" id="page-search-submit" class="button" value="Search Pages"></p>
            </div>
            </form>
    
            <form id="cpts-filter" action="/wp-admin/edit.php" method="get">
            <div class="search-box" style="height:50px">
                <input type="search" id="cpt-search-input" name="s" value="">
                <input type="hidden" name="post_type" value="gallery" /> 
                <input type="submit" name="" id="cpt-search-submit" class="button" value="Search Galleries"></p>
            </div>
            </form>
        <?php
    }
    

    Results

    dashboard widget

    &

    dashboard widget search results