Created
August 23, 2014 23:05
-
-
Save rileypaulsen/b58d582def11564b2b54 to your computer and use it in GitHub Desktop.
Use authentication with the JSON REST API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Note: requires the Basic Auth plugin | |
$username = 'username'; | |
$password = 'password'; | |
$args = array( | |
'headers' => array( | |
'Authorization' => 'Basic ' . base64_encode( $username . ':' . $password ), | |
), | |
); | |
$queryFilters = array( | |
'posts_per_page'=>-1, | |
's'=>'search query', | |
'tax_query' => array( | |
array( | |
'field'=>'slug', | |
'taxonomy'=>'designation', | |
'terms'=>array('staff','student','alumni') | |
) | |
) | |
); | |
$query = '?'; | |
foreach($queryFilters as $key => $value): | |
$query .= "filter[$key]=".maybe_serialize($value)."&"; | |
endforeach; | |
echo '<pre>'; | |
print_r($query); | |
echo '</pre>'; | |
$employees = wp_remote_get(get_json_url().'/posts/'.$query, $args); | |
echo '<pre>'; | |
print_r(json_decode($employees['body'])); | |
echo '</pre>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment