Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'posts_join', 'property_search_join' );
- function property_search_join ( $join ) {
- global $pagenow, $wpdb;
- // I want the filter only when performing a search on edit page of Custom Post Type named "property".
- if ( is_admin() && 'edit.php' === $pagenow && 'property' === $_GET['post_type'] && ! empty( $_GET['s'] ) ) {
- $join .= 'LEFT JOIN ' . $wpdb->postmeta . ' ON ' . $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
- }
- return $join;
- }
- add_filter( 'posts_where', 'property_search_where' );
- function property_search_where( $where ) {
- global $pagenow, $wpdb;
- // I want the filter only when performing a search on edit page of Custom Post Type named "property".
- if ( is_admin() && 'edit.php' === $pagenow && 'property' === $_GET['post_type'] && ! empty( $_GET['s'] ) ) {
- $where = preg_replace(
- "/\(\s*" . $wpdb->posts . ".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
- "(" . $wpdb->posts . ".post_title LIKE $1) OR (" . $wpdb->postmeta . ".meta_value LIKE $1)", $where );
- }
- return $where;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement