Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. <?php
  2. function ci_admin_posts_filter( $query )
  3. {
  4. global $pagenow;
  5. if ( is_admin() && $pagenow=='edit.php' && isset($_GET['ADMIN_SEARCH_FIELD_NAME']) && $_GET['ADMIN_SEARCH_FIELD_NAME'] != '') {
  6.  
  7. $query->query_vars['meta_value'] = $_GET['ADMIN_SEARCH_FIELD_NAME'];
  8.  
  9. }
  10. }
  11.  
  12. add_filter( 'parse_query', 'ci_admin_posts_filter' );
  13.  
  14. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  15.  
  16.  
  17. function ci_admin_posts_filter_restrict_manage_posts()
  18. {
  19.  
  20. /** Ensure this is the correct Post Type*/
  21. if($_GET['post_type'] !== 'product')
  22. return;
  23.  
  24. global $wpdb;
  25.  
  26. $sql = 'SELECT post_title FROM '.$wpdb->posts.' where post_type="manufacturer" ORDER BY post_title asc';
  27. $fields = $wpdb->get_results($sql, ARRAY_N);
  28. ?>
  29. <select name="ADMIN_SEARCH_FIELD_NAME">
  30. <option value=""><?php _e('Search By Manufacturers', 'ci'); ?></option>
  31. <?php
  32. $current = isset($_GET['ADMIN_SEARCH_FIELD_NAME'])? $_GET['ADMIN_SEARCH_FIELD_NAME']:'';
  33.  
  34. foreach ($fields as $field) {
  35. if (substr($field[0],0,1) != "_"){
  36. printf
  37. (
  38. '<option value="%s"%s>%s</option>',
  39. $field[0],
  40. $field[0] == $current? ' selected="selected"':'',
  41. $field[0]
  42. );
  43. }
  44. }
  45. ?>
  46. </select>
  47.  
  48. <?php
  49. }
  50.  
  51. add_action( 'restrict_manage_posts', 'ci_admin_posts_filter_restrict_manage_posts' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement