• Resolved fersamp

    (@fersamp)


    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

    https://ww.wp.xz.cn/plugins/rest-api/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

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