Are you making the GET request against the path /sito2/Wordpress/wp-json/wp/v2/posts/? Or the URL for the posts endpoint (yourdomain.tld/wp-json/wp/v2/posts/)?
Ah, I see the problem. You’re using the default permalink settings. You have two options:
- Use one of the “pretty” permalink options (docs here), or…
- If you want to keep the default permalink settings, manually specify the route using
?rest_route=/wp/v2/posts/(example below, more info here)
Example of the second option:
http://www.michelefaccini70.no-ip.org/sito2/Wordpress/?rest_route=/wp/v2/posts/
Thanks a lot…it works ! Now next step for me is to register automatically my users to WordPress as they register to my site.I installed WP REST User plugin (see the following link : https://ww.wp.xz.cn/plugins/wp-rest-user/) and now I have to figure out how to use it (not a programmer…).
The following seems to work :
/* register user to WordPress */
$json_string_data = '{"username" : "'.$usrnm. '", "password" : "' . $password . '", "email" : "' . $email . '"}';
$ch = curl_init('http://www.michelefaccini70.no-ip.org/sito2/Wordpress/?rest_route=/wp/v2/users/register');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_string_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($json_string_data))
);
$result = curl_exec($ch);
-
This reply was modified 7 years, 6 months ago by
michelefaccini.
-
This reply was modified 7 years, 5 months ago by
bcworkz. Reason: code fixed
Now next step for me is to login in automatically my users to WordPress as they are logged in to my site.