Title: Problem with parameter in register route method
Last modified: August 31, 2016

---

# Problem with parameter in register route method

 *  Resolved [fersamp](https://wordpress.org/support/users/fersamp/)
 * (@fersamp)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/problem-with-parameter-in-register-route-method/)
 * Hi,
    I have problem with register_routes(): I have to do a query to get some 
   thing but I don’t manage to pass a date to my function.
 * This is my route registration:
 *     ```
       register_rest_route( $this->namespace, '/' . $this->rest_base . '/todayEvents', array(
       		array(
       		'methods'         => WP_REST_Server::READABLE,
       		'callback'        => array( $this, 'getTodayEvents' ),
       		'args'            => array(
       							 'posts_per_page'     => 4,
       							 'offset'     => 1,
       							 'filter'     => date("Y-m-d")
       							),
       		),
       		'schema'          => array( $this, 'get_public_item_schema' ),
       		) );
       ```
   
 * In getTodayEvents($request) method I need to retrieve the date passed but I don’t
   know how.
 * In my function
    `$dateFilter = $request['filter'];`
 * $dateFilter is empty.
 * I need to use the same function and passing different params because I have to
   filter my results by different date, so I think it’s better to use a generic 
   function and passing different arguments.
 * Thank you

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Daniel Bachhuber](https://wordpress.org/support/users/danielbachhuber/)
 * (@danielbachhuber)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/problem-with-parameter-in-register-route-method/#post-7075511)
 * The default values aren’t present in the request because you’re registering your
   arguments incorrectly. Please [review the documentation](http://v2.wp-api.org/extending/adding/)
   thoroughly.
 * Your argument registration should be something like this (untested):
 *     ```
       'args' => array(
       	'posts_per_page' => array(
       		'type'    => 'integer',
       		'default' => 4,
       	),
       	'offset' => array(
       		'type'    => 'integer',
       		'default' => 1,
       	),
       	'filter' => array(
       		'type'    => 'string',
       		'default' => date("Y-m-d"),
       	),
       )
       ```
   
 *  Plugin Author [Daniel Bachhuber](https://wordpress.org/support/users/danielbachhuber/)
 * (@danielbachhuber)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/problem-with-parameter-in-register-route-method/#post-7075512)
 * Sorry. Just to confirm, you should be using [WP-API v2](https://wordpress.org/plugins/rest-api/)
   and WordPress 4.4 or higher. This support forum is for the deprecated WP-API 
   v1.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Problem with parameter in register route method’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/json-rest-api_2e3641.svg)
 * [WP REST API (WP API)](https://wordpress.org/plugins/json-rest-api/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/json-rest-api/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/json-rest-api/)
 * [Active Topics](https://wordpress.org/support/plugin/json-rest-api/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/json-rest-api/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/json-rest-api/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Daniel Bachhuber](https://wordpress.org/support/users/danielbachhuber/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/problem-with-parameter-in-register-route-method/#post-7075512)
 * Status: resolved