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 for your custom endpoint, by using WP_Query
instead of get_posts()
.
Thanks to @DenisUyeda for correcting the typo.
Related Posts:
- Why are tags from the header showing up on my WordPress site? [closed]
- Why won’t wp_mail() let me set the From: header when plain old PHP mail() will?
- How does one suppress a 404 status code in a WordPress page?
- Admin bar and fixed header issue?
- How to remove rest api link: in http headers?
- disable wordpress canonical tag meta
- Disable h1 and h2 from rich text editor combobox
- Recommended location to set response headers?
- Is it safe to fix Access-Control-Allow-Origin (CORS origin) errors with a php header directive?
- Getting “Cannot modify header information – headers already sent” error on wp-admin only whenever any plugin is activated
- Additional Option on Custom Header admin
- How can I use CURLOPT_USERPWD in wp_remote_post?
- Putting content into header.php without using wp_head
- Setting Last Modified HTTP Header on static Home Page
- If Modified Since HTTP Header
- Image slider to display at the very top of home page
- Remove rel=shortlink from HTTP header
- Getting redirect to happen before header output
- How do you log a user out with wp_logout?
- Indenting (tabbing) WP_head
- Change the headers content type with wp_remote_post
- Different custom header image on different page
- Why I can’t add a script-code into theme-settings without 403-forbidden?
- HTTP Header on specific page is application instead of text
- Auto-refresh page every minute?
- Is it wrong to put header tags inside WordPress help tabs? [closed]
- Authenticate a user for current request
- Remove link around logo
- Want to make header and footer CMS driven sothat Editors can modify its content from wordpress admin section
- Facebook embeds loading the wrong language
- Header: Include Date Published and Date Modified
- Page source contains an http item that makes page insecure; but in php files it’s written as https!
- Cleanup Body_Class
- Banner in WordPress
- Google Tag Manger – no-script Code Not Found
- Determine what pages are in my header [closed]
- How to remove main domain header title from after sub domain header title
- I want to hide header in the static homepage that I am working on [closed]
- Remove all WordPress HTTP headers (not in-source embeds)
- WordPress 502 | Header Upstream send too big
- Creating dynamic header and footer files
- Strange 403 header response
- 404 or ugly page on IE, but Firefox, Chrome looks perfect
- Changing header text from uppercase to normal [closed]
- Safe to start a php session on get_header action?
- My header not showing up [closed]
- How to Access Script Tags in Header
- H1 tags for header image?
- Where are my js and css links in header?
- Why does WordPress allow inserting tags into posts?
- Is there a way to get minimal WordPress functions for iframed content?
- Problems accessing stylesheets/scripts loaded in WP header
- Rotate images in header based on date
- Why does WP load so many files in the head of source code? How do I optimize it?
- Trying to set a cookie based on $_POST parameter
- How to add some lines to the wp-login.php header via functions.php?
- How to Customize Wp Default Title and a prefix
- Hook to change HTTP response headers
- allowed_http_origins() only works in theme functions.php
- Insert stylesheet into WordPress header?
- How to register and set http/2 server prefetch for a specific asset?
- Header with content
- WordPress Template not getting my Sub-Header File
- How to add social follow button to header? [closed]
- Include two headers
- Empty header tags [closed]
- Insert Facebook button into header [closed]
- What is this HTTP_REFERRER “WordPress/4.1.2”
- Empty lines in header, how to remove them
- Benefits to using CSS for header image instead of html img tag [closed]
- Export Header and Footer
- Custom headers in WordPress, are there also custom footers?
- Point get_header() to different plugin
- How do I begin debugging where the description meta tag is set for my categories?
- How do I get the Social Media Plugin to show up in my Twenty Eleven child theme’s header?
- Inserting iframe right after on header.php
- How to add script right after ?
- Adding more tabs to horizontal navigation bar
- Code needs wrapper/container to put footer back in, but where?
- Dynamic height in custom header image panel
- How can I remove or change the tooltip of an icon
- Design Header meta on single posts wordpress
- Including PHP files in header.php
- How do I modify the tag on my Category Archive page?
- Remove a link in the header
- Remove server response header
- Using a nonce Content Security Policy header for style-src for inline style elements returns errors
- How can I use an iframe element as my header media?
- How to make my banner (logo image) position on the center
- Easiest way to use relative URLs in my WordPress header
- Should I use do_action in the header file?
- Update Code to be Compatible with WP 5.3 (‘cannot modify header information’ warning)
- set cookies on certain page only
- Twenty seventeen header is not responsive
- 3 WP installations on the same domain, with the same header
- How to make custom_header_setup() image as background image?
- Video Header in 2016 theme
- WordPress site screwed up after adding Facebook Pixel inbetween header tags
- WordPress cookie issue on login: “ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.”
- Enable CORS for getting an inline SVG by URL