What’s wrong with my call to register_rest_route() ? Is it the way I’m
trying to access it?
This is the correct way to access that endpoint:
The route I’m trying to access is
http://site.test/wp-json/mchs/v1/search/[email protected]
But then you’re getting the 404 error because the path variable in the second parameter below, is not in the correct form of (?P<parameter name>regular expression pattern), including the round brackets ( ( and ) ):
register_rest_route( 'mchs/v1', '/search/?P<search_email>\S+',
So you’re just missing the round brackets and thus just add them, i.e. use (?P<search_email>\S+), and the 404 error would be gone:
register_rest_route( 'mchs/v1', '/search/(?P<search_email>\S+)',
Additionally, you should always set a permission_callback, even for public REST API routes, to avoid a _doing_it_wrong notice. 🙂
Related Posts:
- wordpress custom endpoint multiple params
- Continue execution after WP REST API response
- what is the best practice to add new field to an api route
- Building a REST API for your web app exposes primary keys of DB records?
- Cant register rest routs from class instance
- Validate and Sanitize WP REST API Request using WP JSON Schema?
- Flatten Responses returned via WP REST API via WP_Error for obfuscation
- Looping through and combining calls to Woocommerce REST API
- get Woocommerce product format json for WP_Query
- Properly process a custom WP REST API request (Authenticate, Authorize + Validate)?
- How to pass and validate nonce in custom REST routes
- Query posts by custom taxonomy slug in WP REST API?
- oneOf JSON Schema validation not properly working for custom post meta value?
- Authenticate + Authorize WP REST API request before built-in WP JSON Schema Payload Validation?
- WordPress REST API – Custom field not added to pages
- Custom rest fields not loaded in rest api cpt response
- cURL 28 error after switch from to brew php 7.2 on localhost
- Uninstalling a plugin: delete all options with specific prefix
- Detect a focus on wp_editor
- Creating a post with the REST API, curl and oauth returning 401 error
- Display a text message if the shortcode is not found?
- How to use a frontend URL with a Plugin
- Utilize WP-CLI from inside WordPress, not SSH
- Why is PHP Cookie via plugin only set when logged in as Admin and not regular users? and other questions
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- Loading page template into shortcode
- Using wp_get_image_editor in a standalone script
- WordPress Ajax Custom Query – High CPU LOAD
- allow users to publish without admin approval
- action hook wp_head higher priority as all other plugins/hooks
- Do my defines need to be unique?
- How to filter posts by post format “standard” from wp-json api?
- What does $wpdb->get_row return?
- woocommerce subscriptions – get expiration date [closed]
- Delete a WordPress transient from a shortcode on Page/Post update
- Plugin CSS not enqueing
- PHP Fatal error: Uncaught mysqli_sql_exception: Table doesn’t exist in wordpress/wp-includes/wp-db.php
- Woocommerce hook run after an Order been created through REST API
- Woocommerce api: create product with images – bad request
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- How to call plugin function per site in a multisite?
- Are nonces in WP REST API optional by default?
- How wp-cron can run in background if PHP is single threaded?
- Options API get_option() and update_option() Not Correctly Updating or Returning
- wp_head function not outputting
- How to make own crop image function for WordPress plugin
- “Undefined index” error when saving empty array with checkboxes
- Buddypress update user avatar image via REST
- wp_insert_post: array only. wp_update_post: array|object (?)
- Is it save to use eval for a jQuery callback method coming from the database?
- Scheduling an event inside plugin class is not working
- How to Change CSS Colors from Custom Plugin Settings Page
- Passing the name of selected color from the custom component to `render_callback`
- Any ideas why I am getting “I’m getting “wp-admin/admin-ajax.php 401 (Unauthorized)”
- wordpress frontend editor to add extra css to website
- PHP: How to access db the right way in plugin?
- select a single val though a table in wordpress
- WordPress – Get Posts with Category data
- Add a custom WooCommerce settings tab with sections
- PHP using external anonymous function inside class
- Using ACF Relationship field to set post type to draft or published status
- Require()/Include() post template adding extra content
- Add Pre-Defined Value to Click Counter in WordPress
- How to route root path / to /xyz in nginx?
- How can i avoid duplicate same post in wp?
- Drop down question
- code that I can run, or a plug in to show what sql tables something pulls information from
- Automatic email message after manual user approval
- custom mailchimp form using HTTP API
- How to override theme’s public static function inside of a trait?
- pass datetime using wp_localize_script to frontend from settings page
- add custom metabox to media library custom widget
- Display attached images of a page or post that are insetred using gallery
- overwrite wordpress gallery with custom gallery shortcode
- Enqueue sripts and styles only if function is called
- Add widget area from visual editor
- Register/enqueue scripts only on certain admin pages
- Looping through custom data in a custom table to display all items in a post
- Showing how many times is plugin activated or deactivated
- not able to access $_POST on backend profile update
- Custom Plugin Develoment, Form Action
- WordPress Query Crashes Browser
- How to Request a User to Register on Landing at a Site, Then Automatically Delete the Users Password on Logout?
- Plugin Modification Change Functionality For Logged User Only
- Force CSV download with template_redirect
- INCOMING: Wall of code for form and $_POST, not updating custom field’s value
- add shortcode heading showing multiple time
- How to print redirected query string variables to the page?
- WP multisite network plugin fails to see classes loaded with spl autoload
- AJAX & PHP | Call a specific PHP function from a PHP file via AJAX?
- What is this mark for “? function()” [closed]
- using a shortcode in a hyperlink
- Headers already sent error with get_template_part in REST API call
- Login user into magento using wordpress account
- REST API custom endpoints for metaboxes
- Customize create table SQL statement in any WordPress plugin
- wp_register_script – illegal string offset
- Accessing Correct Database to Create REST API Endpoint
- Does it make sense to sanitize the output of an SVG file?
- check difference between two timestamp in custom plugin