The Posts endpoint accepts a slug
parameter when querying for posts, so if you can get the slug from the URL, then you can make request to /wp-json/wp/v2/posts?slug=<slug>
.
So if the URL is http://example.com/hello-world/
and you know the slug is hello-world
, then for example in JavaScript, you can do something like:
fetch( 'http://example.com/wp-json/wp/v2/posts?slug=hello-world' )
.then( res => res.json() )
.then( posts => console.log( posts[0].id ) );
Or you could create a custom endpoint.. if you’ve got control over the WordPress site. See this for more details.
Related Posts:
- WordPress REST API “rest_authentication_errors” doesn’t work external queries?
- WP_REMOTE_POST Requests are being blocked by API provider [closed]
- How to change the date and time in REST API for comments?
- How to display relations via wordpress Rest API
- register/login api
- WordPress REST API in Integromat: How to overcome “Sorry, you are not allowed to list users / edit this…”
- Remove unwanted fields from WP API response
- WordPress API “code”:”rest_no_route” with Custom Route
- Woocommerce API for calling products by Category ID
- Get post count in wp rest API v2 and get all categories
- Query WP REST API v2 by multiple meta keys
- How do I cache (core) API requests?
- WP REST API only returning partial list of users
- Is there a way to get protected meta fields through any of the available built-in WordPress APIs? (xmlrpc, wp-json)
- Are there server performance benefits to fetching only specific fields when querying the REST API?
- Retrieving pages with multiple tags using REST API
- WordPress Rest API: How do we validate with our custom API key?
- Does pre_get_posts affect REST API responses?
- How do I use the WP REST API plugin and the OAuth Server plugin to allow for registration and login?
- WP API : date_query parameter
- Hiding API routes list
- Get more than 10 posts in a specific category with the wordpress api
- Can we access the REST request parameters from within the permission_callback to enforce a 401 by returning false?
- Create post with REST API in php with file_get_contents
- x-wp-nonce is not allowed by Access-Control-Allow-Headers in preflight response
- How to filter users on custom meta fields in WP JSON v2?
- Gutenberg Custom Block Getting All Posts
- node-wpapi: how to handle authentication?
- Get all tags not just first 10 with wp api 2.0
- Passing a borrowed nonce through Postman fails
- How to add WP API and JS featured image attachment
- Display post title from WordPress excluding a string via API
- How send get request to external api with username and password
- Get all PDF files from page with WordPress API
- is it possible to filter a rest api endpoint by using a registered rest field?
- Use the backbone.js client to save custom post type meta
- No ‘Access-Control-Allow-Origin’ when call rest API
- Woocommerce api: create product with images – bad request
- Adding custom end points, No error line
- “No Access-Control-Allow-Origin header is present” even though it is in the entry file
- Update a post based on results from GET request to another server
- WP API post__not_in is not working
- Validate rest-api call on create
- How to edit feature image with XML RPC?
- Core function to check if a rest namespace exists
- Is there a way to download only the Rest API part of WordPress?
- WordPress REST Api get posts by ID
- Creating a WordPress Post via REST API – HTML or Markdown?
- Custom REST endpoint not working to retrieve single posts (“rest_no_route”)
- WordPress HTTP API NTLM Authentication
- [Zapier + WP Webhooks Pro]: Custom Fields get cut off at first comma or semicolon
- REST API and filtering by meta value
- Rest API: trouble receiving response through script (browser and Postman display correctly)
- How to use Python to create a Post in WordPress?
- Is there a way I can fetch the WordPress Developer Code References with an API?
- WP REST API and Access-Control-Allow-Origin
- Cannot use WordPress Application Passwords: “code”: “rest_no_route” “status”:404 for /wp-json/wp/v2/users/me/application-passwords
- WordPress REST API – get custom taxonomy category posts
- Allow REST API Endpoint to specific user and hide from public
- How to add Relations of a CCT from JetEngine via WordPress Rest API
- Can I overwrite default WordPress Json API For no more pages text
- trigger WordPress rest any API call
- Secure WordPress API, how?
- Escape commas in REST API
- how to create JSON array [] for REST response?
- How do i post data to url with fields?
- Help to create the best plugin settings!
- How to receive JSON payload from a digital device
- The REST API encountered an error in wordpress?
- Adding Amchart Interface to WordPress API
- Connecting WordPress with an External API
- Deleting media using the WordPress Rest API
- WordPress single page website redirect to index.html
- Autotrader API Integration
- REST API get featured image source for custom post type
- Extending the API I created to return category names
- API request forbidden when requesting from same domain
- How to update WordPress Plugins in your own maintance application?
- Update post / page using API + python
- External api call using wordpress
- Restrict Image Sizes and Dimensions when Uploading via the WP Mobile App
- JS WordPress API fetch no response headers
- Issue with API after 6.2 update
- Adding Microsoft Teams Incoming Webhook to WordPress, Problem with Rest Route?
- wordpress rest api authentication failed
- Hide custom posts from certain taxonomy in rest api
- How to submit a button automatically after every scheduled hours?
- WP REST API returns blank response if post is too long
- 401 Error when trying to make a REST API call to site
- Can I define multiple callback methods depending on the call method?
- Passing Meta array in wp-rest api
- How to make a WP REST API query with meta_query in WP4.7?
- Inserting custom post meta value using WP-REST API
- WP API querying a custom post type and a custom field
- Exclude objects from WordPress API based from ACF field using rest_prepare_{$post_type}
- WordPress REST API calls that depend on the WordPress User
- WordPress output data to another website and pull data
- Set logged in user based on API response
- REST api header link href
- How Can I keep password protected posts in the json requests but not on frontend queries?