Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'restrict_manage_posts', 'wpse45436_admin_posts_filter_restrict_manage_posts' );
- function wpse45436_admin_posts_filter_restrict_manage_posts(){
- $type = 'property';
- if (isset($_GET['post_type'])) {
- $type = $_GET['post_type'];
- }
- //only add filter to post type you want
- if ('property' == $type){
- //change this to the list of values you want to show
- //in 'label' => 'value' format
- $values = array(
- 'featured' => 'featured',
- );
- ?>
- <select name="ADMIN_FILTER_FIELD_VALUE">
- <option value=""><?php _e('Filter By ', 'wose45436'); ?></option>
- <?php
- $current_v = isset($_GET['ADMIN_FILTER_FIELD_VALUE'])? $_GET['ADMIN_FILTER_FIELD_VALUE']:'';
- foreach ($values as $label => $value) {
- printf
- (
- '<option value="%s"%s>%s</option>',
- $value,
- $value == $current_v? ' selected="selected"':'',
- $label
- );
- }
- ?>
- </select>
- <?php
- }
- }
- add_filter( 'parse_query', 'wpse45436_posts_filter' );
- function wpse45436_posts_filter( $query ){
- global $pagenow;
- $type = 'property';
- if (isset($_GET['post_type'])) {
- $type = $_GET['post_type'];
- }
- if ( 'property' == $type && is_admin() && $pagenow=='edit.php' && isset($_GET['ADMIN_FILTER_FIELD_VALUE']) && $_GET['ADMIN_FILTER_FIELD_VALUE'] != '') {
- $query->query_vars['meta_key'] = '_meta_featured';
- $query->query_vars['meta_value'] = 'on';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement