URL endpoint with HTML

I’m using WordPress endpoints to render another template on a post page. How can I add .html to the end of the URL that using the endpoint? Example: Normal URL: example.com/angry-birds Normal URL with endpoint: example.com/angry-birds/play Here are the results I’m trying to achieve: example.com/angry-birds.html and example.com/angry-birds/play.html 0

add_rewrite_endpoint() and Custom Post Type Archive

I’ve got a custom post type. Let’s call it books. I’m adding a new rewrite endpoint called pages. I want the url /books/pages/2/ to work but I don’t see any rewrite rules generated by WordPress for this. I can manually add the rewrite rules for this specific example, but I’m looking for a way to … Read more

Removing “category” from URLs then “add_endpoint()” won’t work…

For example, the original URL would be http://localhost/category/sub_category/. What I want is http://localhost/sub_category/, furthermore, I want to add an endpoint to the URL which looks like http://localhost/sub_category/endpoint/. I’ve removed the “category” from the URL successfully by following this tutorial https://jonnyjordan.com/blog/how-to-remove-category-from-your-urls-in-wordpress/ . But once I remove the “category” from the url, the add_rewrite_endpoint( ‘endpoint’, EP_CATEGORIES ) … Read more

Extending wp JavaScript base class to make a post request to a custom REST endpoint

I’ve defined a REST endpoint /my-plugin/v1/post-read to show whether a post has been read or not, per-user. In PHP, my plugin keeps track of this depending on page views while logged in. I’m now trying to add a front-end AJAX control to let users manually set a post as “unread” or “read”. I’ve read that … Read more

Rest API Custom Endpoint with space character

I’m trying to add an endpoint with the following: register_rest_route(‘namespace/v1′,’custom-search/(?P<search>[a-zA-Z\s]+)’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘gm_custom_search_callback’ ) ); It registers the route, but won’t recognise when I add a space character i.e. %20 or pass a string with a ” ” in, I can’t see anywhere that would suggest how this should be achieved, … Read more

Request object for validate_callback

I’m trying to define a new REST Api endpoint based on WP REST API (version 2) and have question relating to what arguments are available to the validate_callback and sanitize_callback. Is the Request object made available for these callbacks? For example: add_action( ‘rest_api_init’, function () { register_rest_route( ‘myplugin/v1’, ‘/author/(?P<id>\d+)’, array( ‘methods’ => ‘GET’, ‘callback’ => … Read more

How to create an endpoint without creating sub endpoints?

I’m trying to create a new endpoint using add_rewrite_endpoint(). Here’s my code: // Add query var. add_filter( ‘query_vars’, function( $vars ) { $vars[] = ‘my-endpoint’; return $vars; } ); // Add endpoint. add_action( ‘init’, function() { add_rewrite_endpoint( ‘my-endpoint’, EP_AUTHORS ); } ); I can now visit example.com/author/my-endpoint which is great but “sub” endpoints also seem … Read more