1

I have a WordPress page that show some fields that are given in the query string

for example I can call the page with :

www.mysite.com/mypage?testparam=myvalue

and in the page I have this minimal code:

[insert_php]global $wp_query;if (isset($wp_query->query_vars['testparam'])){
$testparam= urldecode($wp_query->query_vars['testparam']);}
[/insert_php]

testparam is: [insert_php]var_dump ($testparam);[/insert_php]>

curl "http://www.example.com/wp-json/wp/v2/pages?slug=test-params&meta_key=test&_wp_json_nonce=4355d0c4b3&query_vars_hash=1"

So this is working well when using the standard web-way. Is there a way to pass the parameter also when requesting via the rest api ?

I tried with

curl "http://www.example.com/wp-json/wp/v2/pages?slug=mypage&testparam=testvalue"

But it seems that the testparm is nowhere to be found.

  • You want to modify the WP_Query, and so the response, or to process the data inside the page template and do an action (ie send an email)? – Laxmana Mar 7 '17 at 14:08
  • the requirement for example is that I would be able to pass a testparam and the page should be able to display that parameter [via the rest api]. – dawez Mar 7 '17 at 15:42
  • I think you misunderstanding what a RESTful API is. There is no pages but endpoints and they do not display but respond to a request and a method. Nevertheless, it is possible to pass a parameter and get a response based on that parameter. The docs are not very good at the moment but it should give you a hint where to start. Also this might help. – Laxmana Mar 7 '17 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.