Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement