remove TODO in category filter type and allow filter by description
This commit is contained in:
parent
8048fa3d84
commit
af9d7c81e8
|
@ -259,12 +259,18 @@ class TAINACAN_REST_Controller extends WP_REST_Controller {
|
|||
// handle core field
|
||||
if( array_key_exists("key", $a) ){
|
||||
$field = new Tainacan\Entities\Field($a['key']);
|
||||
if( strpos( $field->get_field_type(), 'Core') !== false ){
|
||||
if( strpos( $field->get_field_type(), 'Core_Title') !== false ){
|
||||
$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;
|
||||
} else if( strpos( $field->get_field_type(), 'Core_Description') !== false ) {
|
||||
$args[ 'post_content_in' ] = [
|
||||
'relation' => ( isset( $request_meta_query['relation']) ) ? $request_meta_query['relation'] : 'AND' ,
|
||||
'value' => ( is_array( $a['value'] ) ) ? $a['value'] : [$a['value']]
|
||||
];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ class Category extends Field_Type {
|
|||
]);
|
||||
|
||||
$this->set_form_component('tainacan-form-category');
|
||||
// TODO: Set component depending on options. If multiple is checkbox. if single, select. etc.
|
||||
$this->set_component('tainacan-category');
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ class Items extends Repository {
|
|||
{
|
||||
parent::__construct();
|
||||
add_filter( 'posts_where', array(&$this, 'title_in_posts_where'), 10, 2 );
|
||||
add_filter( 'posts_where', array(&$this, 'content_in_posts_where'), 10, 2 );
|
||||
}
|
||||
|
||||
public function get_map() {
|
||||
|
@ -333,4 +334,26 @@ class Items extends Repository {
|
|||
}
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* allow wp query filter post by array of content
|
||||
*
|
||||
* @param $where
|
||||
* @param $wp_query
|
||||
* @return string
|
||||
*/
|
||||
public function content_in_posts_where( $where, $wp_query ) {
|
||||
global $wpdb;
|
||||
if ( $post_content_in = $wp_query->get( 'post_content_in' ) ) {
|
||||
if(is_array( $post_content_in ) && isset( $post_content_in['value']) ){
|
||||
$quotes = [];
|
||||
foreach ($post_content_in['value'] as $title) {
|
||||
$quotes[] = "'" . esc_sql( $wpdb->esc_like( $title ) ). "'";
|
||||
}
|
||||
}
|
||||
|
||||
$where .= ' '.$post_content_in['relation'].' ' . $wpdb->posts . '.post_content IN ( ' .implode(',', $quotes ) . ')';
|
||||
}
|
||||
return $where;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue