Skip to main content
deleted 54 characters in body
Source Link
fcb1900
  • 101
  • 3

I got it. I have to check, if in array is "['meta_query'][0]['value']" set or notthat working :)

add_filter('rest_test_query''rest_myRoute_query', function($args, $request) {
    
    $args['meta_query']$fields = array('myCustomField');
  
  foreach array(
  $fields as $field) {
   'key' if (! =>empty($request[$field])) 'test_1',{
        'value'$args['meta_query'][] =>= esc_sqlarray( $_GET['test_1'] ),
        )
'key'   => );$field,
    
     //echo $args['meta_query'][0]['value'];
  'value' => //print_resc_sql($args$request[$field]);,
    
    if (!empty($args['meta_query'][0]['value'])) {;
        return $args;       }
    }
  
  return $args;
}, 10, 2);

I got it. I have to check, if in array is "['meta_query'][0]['value']" set or not :)

add_filter('rest_test_query', function($args) {
    
    $args['meta_query'] = array(
    array(
        'key'   => 'test_1',
        'value' => esc_sql( $_GET['test_1'] ),
        )
    );
    
     //echo $args['meta_query'][0]['value'];
    //print_r($args);
    
    if (!empty($args['meta_query'][0]['value'])) {
        return $args;       
    }
    
} );

I got that working :)

add_filter('rest_myRoute_query', function($args, $request) {
  $fields = array('myCustomField');
 
  foreach ($fields as $field) {
    if (! empty($request[$field])) {
      $args['meta_query'][] = array(
        'key'   => $field,
        'value' => esc_sql($request[$field]),
      );
    }
  }
 
  return $args;
}, 10, 2);
Source Link
fcb1900
  • 101
  • 3

I got it. I have to check, if in array is "['meta_query'][0]['value']" set or not :)

add_filter('rest_test_query', function($args) {
    
    $args['meta_query'] = array(
    array(
        'key'   => 'test_1',
        'value' => esc_sql( $_GET['test_1'] ),
        )
    );
    
    //echo $args['meta_query'][0]['value'];
    //print_r($args);
    
    if (!empty($args['meta_query'][0]['value'])) {
        return $args;       
    }
    
} );