Custom route for WP-API gives “rest_no_route” value
I may have the answer to this. I had POST in my code, but I was trying to look at the URL through a browser. Make sure you’re using the method you specify.
I may have the answer to this. I had POST in my code, but I was trying to look at the URL through a browser. Make sure you’re using the method you specify.
Both callbacks in the register_rest_field_for_custom_taxonomy_location() function are misspelled. change ‘get_callback’ => ‘location_get_term_meta’, ‘update_callback’ => ‘location_update_term_meta’, to ‘get_callback’ => ‘location_get_term_meta_field’, ‘update_callback’ => ‘location_update_term_meta_field’, Register Code function register_rest_field_for_custom_taxonomy_location() { register_rest_field( ‘location’, ‘location_code’, array( ‘get_callback’ => ‘location_get_term_meta_field’, ‘update_callback’ => ‘location_update_term_meta_field’, ‘schema’ => null, ) );
Couldn’t get it to work. The only solution that I found was to setup a custom endpoint: http://v2.wp-api.org/extending/adding/
Ran into this same issue and I found the answer after many hours and almost giving up. It’s in a bit of code that written to make the Customizer work with playlists. Checkout this comment from /wp-includes/widgets/class-wp-widget-text.php: /** * Enqueue preview scripts. * * These scripts normally are enqueued just-in-time when a playlist shortcode is … Read more
Use below code snippet function video_get_post_meta($object, $field_name, $request) { return array( ‘video’ => array( ‘length’ => get_post_meta($object[‘id’], ‘length’, true), ‘file_name’ => get_post_meta($object[‘id’], ‘file_name’, true), ‘thumbnail_’ => get_post_meta($object[‘id’], ‘thumbnail_’, true), ‘video_url’ => get_post_meta($object[‘id’], ‘video_url’, true), )); } add_action(‘rest_api_init’, function() { register_rest_field(‘post’, ‘video’, array( ‘get_callback’ => ‘video_get_post_meta’, ‘update_callback’ => ‘video_update_post_meta’, ‘schema’ => null ) ); } Output … Read more
You can get it easily by making a GET request to: http://yourdomain.com/wp-json/. You will see your site name, description, url and home…
I’m guessing you haven’t exposed meta_key and meta_value to the REST API with the rest_query_vars filter, so this should do it: function my_add_meta_vars ($current_vars) { $current_vars = array_merge ($current_vars, array (‘meta_key’, ‘meta_value’)); return $current_vars; } add_filter (‘rest_query_vars’, ‘my_add_meta_vars’); Then you can refer to meta_key and meta_value in your query. Be aware that this obviously exposes … Read more
On the “REST API” tab, you should be to enable the new post type to show all the custom fields in the standard WordPress REST API. Also, in each field’s options, you should be able to set if that field should be viewable and/or editable via the API, if you only want to show a … Read more
It’s not so difficult. All you have to do is to add a condition and check if the book_id param is passed. You can even check if this param is correct (for example if the book_id should be a number, then you can check if it is): add_filter( ‘rest_gallery_query’, function( $args ) { if ( … Read more
Solved by this lines: RewriteEngine On RewriteBase / RewriteRule ^wp-json/(.*) /?rest_route=/$1 [L]