For example I have a query with tax and metas and other stuff..
how I can pass it to the rest api so i can call all the data with one call
for example this function
function load_special_args() {
$args = array(
'post_type' => 'post',
'order' => 'DESC',
'posts_per_page' => 100,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => '9995',
),
),
);
return $args;
}
imaging call: /wp/v2/posts?args=load_special_args&term=9995
Because I want a special use i dont want to use the /wp/v2/posts?categories=id
For example I have a query with tax and metas and other stuff..
how I can pass it to the rest api so i can call all the data with one call
for example this function
function load_special_args() {
$args = array(
'post_type' => 'post',
'order' => 'DESC',
'posts_per_page' => 100,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => '9995',
),
),
);
return $args;
}
imaging call: /wp/v2/posts?args=load_special_args&term=9995
Because I want a special use i dont want to use the /wp/v2/posts?categories=id
Share Improve this question edited Sep 13, 2018 at 22:38 user2670708 asked Sep 13, 2018 at 22:07 user2670708user2670708 151 silver badge5 bronze badges1 Answer
Reset to default 1You can create a route for Rest API using the below code. Simply put this code in your function.php file
/* Route For api */
add_action( 'rest_api_init', function () {
register_rest_route('wp/v2', 'test', array(
'methods' => array('GET', 'POST'),
'callback' => 'test',
));
} );
And then simply create a callback function test and put your stuff in to that function
function test(){
// put your stuff here
}