create filter for wp query: create param 'post_title_in' to allow search items with an array with titles
This commit is contained in:
parent
3c95559469
commit
09f1b858b3
|
@ -260,7 +260,10 @@ class TAINACAN_REST_Controller extends WP_REST_Controller {
|
|||
if( array_key_exists("key", $a) ){
|
||||
$field = new Tainacan\Entities\Field($a['key']);
|
||||
if( strpos( $field->get_field_type(), 'Core') !== false ){
|
||||
// $args[ 'post_title_in' ] = ( is_array( $a['value'] ) ) ? $a['value'] : [$a['value']];
|
||||
$args[ 'post_title_in' ] = [
|
||||
'relation' => ( isset( $request_meta_query['relation']) ) ? $request_meta_query['relation'] : 'AND' ,
|
||||
'value' => ( is_array( $a['value'] ) ) ? $a['value'] : [$a['value']]
|
||||
];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -322,14 +322,14 @@ class Items extends Repository {
|
|||
public function title_in_posts_where( $where, &$wp_query ) {
|
||||
global $wpdb;
|
||||
if ( $post_title_in = $wp_query->get( 'post_title_in' ) ) {
|
||||
if(is_array( $post_title_in )){
|
||||
if(is_array( $post_title_in ) && isset( $post_title_in['value']) ){
|
||||
$quotes = [];
|
||||
foreach ($post_title_in as $title) {
|
||||
foreach ($post_title_in['value'] as $title) {
|
||||
$quotes[] = "'" . esc_sql( $wpdb->esc_like( $title ) ). "'";
|
||||
}
|
||||
}
|
||||
|
||||
$where .= ' AND ' . $wpdb->posts . '.post_title IN ( ' .implode(',', $quotes ) . ')';
|
||||
$where .= ' '.$post_title_in['relation'].' ' . $wpdb->posts . '.post_title IN ( ' .implode(',', $quotes ) . ')';
|
||||
}
|
||||
return $where;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue