Trying to add a product search bar to WordPress admin bar backend that will do Woocommerce product search. It will be located in the backend Admin Menu bar a top so that no matter where you are in back end it will allow to search woo’s products. I am close but faulting at small stumbling block. When trying to use the search it is defaulting to post search instead of products.
//Add Search To Admin Bar
function boatparts_admin_bar_form() {
global $wp_admin_bar;
$wp_admin_bar->add_menu(array(
'id' => 'boatparts_admin_bar_form',
'parent' => 'top-secondary',
'title' => '<form method="get" action="'.get_site_url().'/wp-admin/edit.php?post_type=product">
<input name="s" type="text" style="height:20px;margin:5px 0;line-height:1em;"/>
<input type="submit" style="height:18px;vertical-align:top;margin:5px 0;padding:0 2px;" value="Search Products"/>
</form>'
));
}
add_action('admin_bar_menu', 'boatparts_admin_bar_form');
Have it in my child theme’s function.php. Driving me nuts trying to figure it out.
You should add hidden field with post-type parameter:
Also, I add some code for displaying search query in form after form submit and a small fix to the button styles.
Fixed code snippet below:
Search results sample: