GET contra

With this endpoint of the WordPress REST API, you get the negative vote of a post. Below you will find an example of how to use the API.

Endpoint

GET domain.com/wp-json/helpful/contra/{post_id}

@param int $post_id

Example

Here you can find an example of use:

/* Post ID */
$post_id = 1234;

/* Request URL */
$url = 'domain.com/wp-json/helpful/contra/' . $post_id;

/**
 * Here we now enter the user who should publish the post.
 * As password we use the generated password by applications passwords from admin user profile.
 */
$user = '<benutzername>';
$pass = '<applications passwords>';

/* Request header */
$headers = [
    'Authorization' => 'Basic ' . base64_encode($user . ':' . $pass),
    'cache-control' => 'no-cache',
];

/* Request arguments */
$args = [
    'headers' => $headers,
    'method' => 'GET',
];

/* Our request */
$response = wp_remote_get($url, $args);

/* If the request returns an error, the error is output */
if (is_wp_error($response)) {
    print_r($response->get_error_message());
}

$response = wp_remote_retrieve_body($response);
$response = wp_json_decode($response);
$response = intval($response);

echo $response;
Was this post helpful?
Top