Fix filter by core metadata

This is no longer needed. we now also store coremeta values as postmeta
This commit is contained in:
leogermani 2018-11-01 15:57:14 -03:00
parent a5dffbf670
commit a5f9d8bf7d
2 changed files with 62 additions and 18 deletions

View File

@ -163,24 +163,6 @@ class REST_Controller extends \WP_REST_Controller {
foreach ( $request_meta_query as $index1 => $a ) { foreach ( $request_meta_query as $index1 => $a ) {
// handle core metadatum
if( is_array($a) && array_key_exists("key", $a) && ( !isset($request['advancedSearch']) || !$request['advancedSearch'] ) ){
$metadatum = new \Tainacan\Entities\Metadatum($a['key']);
if( strpos( $metadatum->get_metadata_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( $metadatum->get_metadata_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;
}
}
foreach ( $query as $mapped_meta => $meta_v ) { foreach ( $query as $mapped_meta => $meta_v ) {
if ( isset( $a[ $meta_v ] ) ) { if ( isset( $a[ $meta_v ] ) ) {
$args[ $mapped_v ][ $index1 ][ $meta_v ] = $request[ $mapped ][ $index1 ][ $meta_v ]; $args[ $mapped_v ][ $index1 ][ $meta_v ] = $request[ $mapped ][ $index1 ][ $meta_v ];

View File

@ -269,6 +269,68 @@ class Items extends TAINACAN_UnitTestCase {
$this->assertTrue( is_array($test_query) ); $this->assertTrue( is_array($test_query) );
$this->assertEquals(0, sizeof($test_query) ); $this->assertEquals(0, sizeof($test_query) );
}
function teste_meta_query_in(){
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'teste',
'status' => 'publish'
),
true
);
$metadatum = $this->tainacan_entity_factory->create_entity(
'metadatum',
array(
'name' => 'metadado',
'status' => 'publish',
'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Text',
),
true
);
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$i = $this->tainacan_entity_factory->create_entity(
'item',
array(
'title' => 'teste10',
'collection' => $collection,
'status' => 'publish'
),
true
);
$this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum, 'value_10');
$i = $this->tainacan_entity_factory->create_entity(
'item',
array(
'title' => 'test100',
'collection' => $collection,
'status' => 'publish'
),
true
);
$this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum, 'value_100');
// should return 1 items
$test_query = $Tainacan_Items->fetch([
'meta_query' => [
[
'key' => $metadatum->get_id(),
'value' => ['value_10'],
'compare' => 'IN'
]
]
], $collection);
$this->assertEquals(1, $test_query->post_count);
} }
/** /**