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'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.

share|improve this question
    
What functionality are you looking for that the default wordpress search doesn't provide? –  fdsa Jul 14 '12 at 22:56
add comment

1 Answer

up vote 2 down vote accepted

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

share|improve this answer
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.