1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
/** * acf relationship query * @param [type] $args [description] * @param [type] $field [description] * @param [type] $post_id [description] * @return [type] [description] */ function dcs_relationship_query( $args, $field, $post_id ) { $args['post_status'] = 'publish'; $args['post_title_like'] = $args[s]; unset($args[s]); return $args; } add_filter('acf/fields/relationship/query', 'dcs_relationship_query', 10, 3); add_filter( 'posts_where', 'title_like_posts_where', 10, 2 ); function title_like_posts_where( $where, $wp_query ) { global $wpdb; if ( $post_title_like = $wp_query->get( 'post_title_like' ) ) { $where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql( $wpdb->esc_like( $post_title_like ) ) . '%\''; } return $where; } |