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'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 functionnality)?

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.

share|improve this question
    
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
add comment

1 Answer

up vote 1 down vote accepted

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