wordpress api using rest_route for other pages
Actually I was able to figure out with a little modification to Rank’s answer: https://www.example.com/?rest_route=/wp/v2/posts&categories=12
Actually I was able to figure out with a little modification to Rank’s answer: https://www.example.com/?rest_route=/wp/v2/posts&categories=12
WordPress has no system of assigning privileges or access to control to code that runs in functions.php or in an enabled plugin. Therefore if you can get code to run into functions.php or a plugin in your WordPress environment, you can do anything that you can do in PHP in your web hosting environment, and … Read more
How can I add authentication for rest_do_request()? No. This solution to your problems will not work, and it will not save time or effort. In fact, it will require extensive and concerted effort, and lots of time. This despite the entire purpose being to avoid dealing with undocumented PHP code by using the REST API … Read more
Despite you already figured it out or found a solution, since this is a follow-up to the other question, I thought it’d be benefecial to post this answer, so hopefully it helps you. =) WordPress uses the native setcookie() function in PHP for setting the authentication cookies, and $_COOKIE for reading the cookies values. But … Read more
Are you sure that a _doing_it_wrong notice isn’t being issued? You won’t see the notice visibly output on the page because that would break the JSON response. But if you look in the headers of the response you should see a X-WP-DoingItWrong header. It should also appear if you use a plugin like this to … Read more
Thanks to @GTsvetanov from Stackoverflow.com. Missing part of my code is $request->get_json_params(); for getting json request then compare it with schema using rest_validate_value_from_schema() then using rest_sanitize_value_from_schema() for saving proper data to database. $schema = $this->user_playtime_meta_schema(); $val = $request->get_json_params();//<– my mistake $result = rest_validate_value_from_schema( $values, $schema ); if ( ! is_wp_error( rest_validate_value_from_schema( $val, $schema ) ) … Read more
When you enqueue or localize a script you’re doing it specifically for the front end or the admin. If you want to enqueue or localize a script in both, you have to specifically do it for both. This is used to enqueue/localize for the front end add_action( ‘wp_enqueue_scripts’, ‘your_function_front’ ); your_function_front() { wp_localize_script(‘scripts’, ‘myAjax’, array( … Read more
Sorry, you can not use it outside of Guttenberg block. but you can get same result every where in wp-admin by using the following solution, For Detail visit the WP Official Documentation this.posts = {}; this.posts = new wp.api.models.Post(); this.posts.fetch().then( response => { console.log(response); }); The following is an example how i have used it … Read more
I tried to reproduce the issue with the following post type and taxonomy registration code (which I put in the functions.php file of a child theme): add_action( ‘init’, function () { register_post_type( ‘venue’, [ ‘public’ => true, ‘label’ => ‘Venues’, ‘show_in_rest’ => true, ] ); register_taxonomy( ‘country’, ‘venue’, [ ‘public’ => true, ‘label’ => ‘Countries’, … Read more
Using this REST API End Point https://example.com/wp-json/wp/v2/taxonomies I found I had 3 Taxonomies available post_tag, category and series. After seeing series, a custom post type, I knew I had something missing in my code. I finally found an article Working with Custom Post Types in WP-API v2 which describes my issue. Apparently in API V2 … Read more