How to format action_data for WP_REST_Request
-
Hello Forum,
I’m trying to create new redirections directly in a plugin via php and the
WP_REST_Request-Class.I already could create a redirection, but I can’t add the target url properly…
For me it only works to give an empty string as parameter. All other tries throw an error. Here the working code:$request = new WP_REST_Request( 'POST', '/redirection/v1/redirect' ); $request->set_param('status', 'enabled'); $request->set_param('position', 0); $matchdata = ['source' => [ 'flag_regex' => false, 'flag_query' => 'ignore', 'flag_case' => true, 'flag_trailing' => false ]]; $request->set_param('match_data', json_encode($matchdata)); $request->set_param('regex', false); $request->set_param('url', '/here-we-come'); $request->set_param('match_type', 'url'); $request->set_param('title', 'test2'); $request->set_param('group_id', 1); $request->set_param('action_type', 'url'); $request->set_param('action_code', 301); $request->set_param('action_data', ''); $response = rest_do_request( $request );I tried different ways to give the
action_data, but none of them worked:$request->set_param('action_data', '["url": "/here-we-go"]'); $request->set_param('action_data', {"url":"here-we-go"}); $request->set_param('action_data', json_encode(['url' => '/here-we-go'])); $request->set_param('action_data', json_encode("/here-we-go"));Anyone has this woking or know how to do it?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘How to format action_data for WP_REST_Request’ is closed to new replies.