0

I'm looking for a way to expand e customize more this topic

How to filter post listing (in WP dashboard posts listing) using a custom field (search functionality)?

I've a custom post type in the dashboard i've managed to have a small search box with a fixed search function to search a specific meta key. The things is that the search form appears on all the /edit.php pages while i need it only in the specific custom post type edit.php page.

I tried with

if (isset($_GET['post_type']) && $_GET['post_type'] == 'product')

but it doesn't seem to work.

  • Welcome to WPSE Martino, could you add some code to show us how you added the search box? Cheers! – Stephen Harris Mar 12 '12 at 11:05
  • Actually, it's obvious you are following the method in the linked question :D. See posted answer... – Stephen Harris Mar 12 '12 at 11:10
1

I'm assuming you've used the method in the question linked to and are using the restrict_manage_posts filter.

 add_action( 'restrict_manage_posts', 'my_search_box' );
 function my_search_box() {
     // only add search box on desired custom post_type listings
     global $typenow;
     if ($typenow == 'product') {
       //On custom post type 'product' admin page.
       //Add code for search box here
     }
  }
  • Wow, that was fast. It works, I hacked it a little more to filter it only by a specific meta_key. Could be useful to post the whole code, but I don't know how, I'm new here and the comment section is too small. pastebin.com/A3kSD57v – molokom Mar 12 '12 at 11:26
  • No problem! Please remember to mark correct answers by ticking them though :D – Stephen Harris Mar 12 '12 at 11:30

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.