Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. add_action( 'restrict_manage_posts', 'wpse45436_admin_posts_filter_restrict_manage_posts' );
  2. function wpse45436_admin_posts_filter_restrict_manage_posts(){
  3. $type = 'property';
  4. if (isset($_GET['post_type'])) {
  5. $type = $_GET['post_type'];
  6. }
  7.  
  8. //only add filter to post type you want
  9. if ('property' == $type){
  10. //change this to the list of values you want to show
  11. //in 'label' => 'value' format
  12. $values = array(
  13. 'featured' => 'featured',
  14. );
  15. ?>
  16. <select name="ADMIN_FILTER_FIELD_VALUE">
  17. <option value=""><?php _e('Filter By ', 'wose45436'); ?></option>
  18. <?php
  19. $current_v = isset($_GET['ADMIN_FILTER_FIELD_VALUE'])? $_GET['ADMIN_FILTER_FIELD_VALUE']:'';
  20. foreach ($values as $label => $value) {
  21. printf
  22. (
  23. '<option value="%s"%s>%s</option>',
  24. $value,
  25. $value == $current_v? ' selected="selected"':'',
  26. $label
  27. );
  28. }
  29. ?>
  30. </select>
  31. <?php
  32. }
  33. }
  34. add_filter( 'parse_query', 'wpse45436_posts_filter' );
  35. function wpse45436_posts_filter( $query ){
  36. global $pagenow;
  37. $type = 'property';
  38. if (isset($_GET['post_type'])) {
  39. $type = $_GET['post_type'];
  40. }
  41. if ( 'property' == $type && is_admin() && $pagenow=='edit.php' && isset($_GET['ADMIN_FILTER_FIELD_VALUE']) && $_GET['ADMIN_FILTER_FIELD_VALUE'] != '') {
  42. $query->query_vars['meta_key'] = '_meta_featured';
  43. $query->query_vars['meta_value'] = 'on';
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement