1

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.

  • What functionality are you looking for that the default wordpress search doesn't provide? – fdsa Jul 14 '12 at 22:56
3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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