Custom REST API endpoint returns rest_no_route when called via wp-json permalink

The problem is with the bbe_sortables&replace in the permalink: <My URL>/wp-json/bridge/v1/test-data/process/bbe_sortables&replace&_wpnonce=<thenonce> which results in an invalid route, where the supposedly query string is seen as part of the route: /bridge/v1/test-data/process/bbe_sortables&replace&_wpnonce=<thenonce> (the valid route for that URL is /bridge/v1/test-data/process/bbe_sortables) and eventually the REST API throws the rest_no_route error. To fix the problem, use add_query_arg() when generating … Read more

How to add / embed an author into REST data from a custom post type?

I found out how to grab each result and add a link. For the ananda_video_audio post type: add_filter( ‘rest_prepare_ananda_video_audio’, function( $results ) { // These two lines are unique to our code of course $video = new Ananda_Video_Audio( $results->data[‘id’] ); $authors = $video->get_author_IDs(); foreach( $authors as $author_id ) { $results->add_link( ‘author’, rest_url( ‘/wp/v2/users/’ . $author_id … Read more

Using The REST API How To Pull All Custom Posts?

The filter is dynamic, i.e. generated from rest_{$post_type}_query. So for the post post type it’s rest_post_query and for the cpt post type it’s rest_cpt_query Note that REST pagination is available: https://example.com/wp-json/wp/v2/posts?per_page=100&page=1 https://example.com/wp-json/wp/v2/posts?per_page=100&page=2 … The maximum of per_page is to reduce the risk of fatal errors if available resources are exceeded when too many items are … Read more

WordPress 5 WP REST routes – No errors

REST API should always return JSON, so it’s output can be parsed as such. If it’ll return something that is not correct JSON, then your JS scripts may stop working. This is why there should be no errors printed in these requests – such messages break JSON response and make it hard to parse. And … Read more

Add ajax load more function using WP API

I’ve solved the problem, I was made a mistake with the variable pull_page that is inside the click event. I’ve moved the variable outside the event and now all works fine. Here is the updated code! var pull_page = 1; var jsonFlag = true; $(‘#load-more’).on(‘click’, function(e){ e.preventDefault(); if(jsonFlag){ pull_page++; $.getJSON(“/u/wp-json/portfolio/all-posts?page=” + pull_page, function(data){ if(data.length){ pull_page++; … Read more

Detect permalinks when passing querystring in REST API requests

In more recent browsers (everything but IE, essentially), there are some useful APIs for working with URLs that will make this easier: let url = new URL( MY_PLUGIN_WP_REST_API_CONFIG.baseUrl ); url.searchParams.append( ‘per_page’, 100 ); url.searchParams.append( ‘order’, ‘asc’ ); fetch( url.toString() ).then(); With those methods the per_page and order parameters will be added correctly regardless of whether … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)