Last active
July 5, 2019 07:01
-
-
Save imran-khan1/3e1ffc1decbd7593e84c3bc856a4fa6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function ci_admin_posts_filter( $query ) | |
| { | |
| global $pagenow; | |
| if ( is_admin() && $pagenow=='edit.php' && isset($_GET['ADMIN_SEARCH_FIELD_NAME']) && $_GET['ADMIN_SEARCH_FIELD_NAME'] != '') { | |
| $query->query_vars['meta_value'] = $_GET['ADMIN_SEARCH_FIELD_NAME']; | |
| } | |
| } | |
| add_filter( 'parse_query', 'ci_admin_posts_filter' ); | |
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
| function ci_admin_posts_filter_restrict_manage_posts() | |
| { | |
| /** Ensure this is the correct Post Type*/ | |
| if($_GET['post_type'] !== 'product') | |
| return; | |
| global $wpdb; | |
| $sql = 'SELECT post_title FROM '.$wpdb->posts.' where post_type="manufacturer" ORDER BY post_title asc'; | |
| $fields = $wpdb->get_results($sql, ARRAY_N); | |
| ?> | |
| <select name="ADMIN_SEARCH_FIELD_NAME"> | |
| <option value=""><?php _e('Search By Manufacturers', 'ci'); ?></option> | |
| <?php | |
| $current = isset($_GET['ADMIN_SEARCH_FIELD_NAME'])? $_GET['ADMIN_SEARCH_FIELD_NAME']:''; | |
| foreach ($fields as $field) { | |
| if (substr($field[0],0,1) != "_"){ | |
| printf | |
| ( | |
| '<option value="%s"%s>%s</option>', | |
| $field[0], | |
| $field[0] == $current? ' selected="selected"':'', | |
| $field[0] | |
| ); | |
| } | |
| } | |
| ?> | |
| </select> | |
| <?php | |
| } | |
| add_action( 'restrict_manage_posts', 'ci_admin_posts_filter_restrict_manage_posts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment