Skip to content

Instantly share code, notes, and snippets.

@asha23
Created November 7, 2019 15:58
Show Gist options
  • Save asha23/8e7c899fd3d156650835d71d17bb7068 to your computer and use it in GitHub Desktop.
Save asha23/8e7c899fd3d156650835d71d17bb7068 to your computer and use it in GitHub Desktop.
WP API
public function wp_connection()
{
$curl = curl_init();
curl_setopt_array($curl,
[
CURLOPT_URL => "https://www.host.com/wp-json/acf/v3/product",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => "$username:$password",
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER =>
[
"Accept: */*",
"Accept-Encoding: gzip, deflate",
"Cache-Control: no-cache",
"Connection: keep-alive",
"Content-Type: application/json",
"Host: www.host.com",
]
]
);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
print_r($response);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment