Endpoint on Specific Page Slug
Endpoint on Specific Page Slug
Endpoint on Specific Page Slug
A good action to hook in would be template_redirect. There you can query for your endpoint like this: add_action(‘template_redirect’, function() { global $wp_query; // Not your endpoint and not a page/post, we do nothing. if (!isset( $wp_query->query_vars[‘download’]) || ! is_singular()) { return; } // Here goes your magic! […] // And probably a good idea … Read more
WordPress Rest API – Get all posts based on post_meta on custom endpoint
You can create a custom endpoint using the add_feed function. I have used this in the past to create custom iCal feeds. // Initialize the feed function your_add_custom_feed() { // This adds a feed http://example.com/?feed=myfeed add_feed(‘myfeed’, ‘your_create_feed’); } add_action(‘init’,’your_add_custom_feed’); // Create a function to form the output function your_create_feed() { // Query variables are accessible … Read more
So I don’t know what stepTwo.file is, but I presumed it’s a File object instance, and I believe the issue here is that you’re not aware that you didn’t actually need to manually set the Content-Type header because when the request body is a FormData instance, then the content type header will always default to … Read more
You should not GET on a POST only rest callback. The code below creates a POST call only register_rest_route(‘miningRigs/v1’, ‘createRig’, array( ‘methods’ => WP_REST_SERVER::CREATABLE, ‘callback’ => ‘createMiningRig’, )); Check http://localhost/wordpress-site/wp-json/miningRigs/v1 which shows you can only POST on createRig I just copy/paste you code + added the https://pressupinc.com/blog/2013/07/minimum-viable-wordpress-plugin/ then enabled the plugin on 4.9.5 and it … Read more
(Revised answer to properly address the questions in the question..) For Question 1 (JS) How can I get a post object from a custom REST endpoint within a Gutenberg block? So there’s the apiFetch() which you can use to fetch resources from the REST API. But unlike return { children: getEntityRecords() }, return { children: … Read more
By default, the output returned by your endpoint/callback will always be sent as a JSON-encoded string (and the Content-Type header would also be/contain application/json), so you can’t use that callback for sending an XML feed. However, you can use the rest_pre_serve_request hook if you want your REST API route to serve a different type of … Read more
After studying carefully 🤓 the WordPress REST API Handbook concerning Home / REST API Handbook / Extending the REST API / Routes and Endpoints Home / REST API Handbook / Extending the REST API / Adding Custom Endpoints I realized I made a couple of mistakes. Therefore, I wanted to share with you my findings. … Read more
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, ) );