Custom endpoint and X-WP-TotalPages (headers)

I had a quick look and here’s how the headers are set in the WP_REST_Posts_Controller::get_items() method: $response = rest_ensure_response( $posts ); // … $response->header( ‘X-WP-Total’, (int) $total_posts ); $response->header( ‘X-WP-TotalPages’, (int) $max_pages ); // … return $response; where: $total_posts = $posts_query->found_posts; and we could use as @jshwlkr suggested: $max_pages = $posts_query->max_num_pages; You could emulate that … Read more

Retrieving pages with multiple tags using REST API

I ran into the same problem but for posts. I found how to OR or AND tags together here: https://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters To get entries that have both L1 AND L2 AND L3 ; use plus (+) https://example.com/cms/wp-json/pages?filter[tag]=L1+L2+L3 In case somebody else comes along and wants to OR terms together I’ll save you the trouble: To get … Read more

WordPress Rest API

What version of the REST API are you using? If you’re using the version that’s bundled with WordPress 4.4 (ie, v2), you’ll need to change your url to something like http://example.com/wp-json/wp/v2/posts. Reference WP API version 2 docs

wp rest api v2 return json_no_route

OK, i find my answer. Just ask it here and as dear Charles sayed, they answered me, so fast, the answer is: By default, WP-API v1 takes priority over v2. If v1 is installed and activated, then v2 routes are inaccessible. To mitigate this, you’ll need to register either v1 or v2 to a different … Read more

Are there server performance benefits to fetching only specific fields when querying the REST API?

I understand that having less data being downloaded improves the experience to the end user, but my question is related to the actual server performance, would the response be faster? Would adding _fields[]=id&_fields[]=title, etc… to the above url improve server performance? No it would not, and for several reasons. When you ask for a post … Read more

WP API returning SQL results as strings, rather than numbers

The string output type is expected for $wpdb query results, the db data types are not mapped to the corresponding PHP data types. You will have to take care of it yourself, like: $data = [ ‘int’ => (int) ‘123’, ‘bool’ => (bool) ‘1’, ‘string’ => (string) ‘abc’ ]; return rest_ensure_response( $data ); with the … Read more

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