PHP code example of maheshwaghmare / wp-dev-remote-request

1. Go to this page and download the library: Download maheshwaghmare/wp-dev-remote-request library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

maheshwaghmare / wp-dev-remote-request example snippets


wp_dev_remote_request_get( string / array() );

// Example 1:
$response = wp_dev_remote_request_get( 'https://maheshwaghmare.com/wp-json/wp/v2/posts/' );

// Example 2:
$response = wp_dev_remote_request_get( 'https://maheshwaghmare.com/wp-json/wp/v2/posts/?_fields=title' );

// Example 3:
$response = wp_dev_remote_request_get( 'https://maheshwaghmare.com/wp-json/wp/v2/posts/?per_page=5&_fields=title' );

// Example 4:
$response = wp_dev_remote_request_get( array(
    'url' => 'https://maheshwaghmare.com/wp-json/wp/v2/posts/',
) );

// Example 5:
$response = wp_dev_remote_request_get( array(
    'url' => 'https://maheshwaghmare.com/wp-json/wp/v2/posts/?_fields=title',
) );

// Example 6:
$response = wp_dev_remote_request_get( array(
    'url' => 'https://maheshwaghmare.com/wp-json/wp/v2/posts/',
    'query_args' => array(
        'per_page' => 5,
        '_fields' => 'title',
    )
) );

'url' => '',
'query_args' => array(),
'remote_args' => array(
    'timeout' => 60,
),
'expiration' => MONTH_IN_SECONDS,
'force' => false,

// "First" request for URL: https://maheshwaghmare.com/wp-json/wp/v2/posts/
$response = wp_dev_remote_request_get( 'https://maheshwaghmare.com/wp-json/wp/v2/posts/' );
var_dump( $response );
// array(
// 		'success' => true,
// 		'message' => 'Response from live site.',
// 		'data' => array(
//			...
// 		),
// )

// "SECOND" request for URL: https://maheshwaghmare.com/wp-json/wp/v2/posts/
$response = wp_dev_remote_request_get( 'https://maheshwaghmare.com/wp-json/wp/v2/posts/' );
var_dump( $response );
// array(
// 		'success' => true,
// 		'message' => 'Response from transient.',
// 		'data' => array(
//			...
// 		),
// )

// "Third" request for URL: https://maheshwaghmare.com/wp-json/wp/v2/posts/
$response = wp_dev_remote_request_get( 'https://maheshwaghmare.com/wp-json/wp/v2/posts/' );
var_dump( $response );
// array(
// 		'success' => true,
// 		'message' => 'Response from transient.',
// 		'data' => array(
//			...
// 		),
// )

// Load files.
quest for URL: https://maheshwaghmare.com/wp-json/wp/v2/posts/
$response = wp_dev_remote_request_get( 'https://maheshwaghmare.com/wp-json/wp/v2/posts/' );
var_dump( $response );
// array(
// 		'success' => true,
// 		'message' => 'Response from live site.',
// 		'data' => array(
//			...
// 		),
// )

// "SECOND" request for URL: https://maheshwaghmare.com/wp-json/wp/v2/posts/
$response = wp_dev_remote_request_get( 'https://maheshwaghmare.com/wp-json/wp/v2/posts/' );
var_dump( $response );
// array(
// 		'success' => true,
// 		'message' => 'Response from transient.',
// 		'data' => array(
//			...
// 		),
// )

// "Third" request for URL: https://maheshwaghmare.com/wp-json/wp/v2/posts/
$response = wp_dev_remote_request_get( 'https://maheshwaghmare.com/wp-json/wp/v2/posts/' );
var_dump( $response );
// array(
// 		'success' => true,
// 		'message' => 'Response from transient.',
// 		'data' => array(
//			...
// 		),
// )