Use PHP’s strtotime()
function to retrieve the timestamp for the date fourteen days ago, then date()
to cast it into an ISO 8601-compliant string which can be passed into the after
parameter.
I’m using sprintf()
here to insert the date just to keep things a bit cleaner and avoid a mess of concatenation.
$url = sprintf(
'https://example.com/wp-json/wp/v2/posts?after=%s&page=%d',
date( 'c', strtotime( '-14 days' ) ),
$page
);