I connected to my Wordpress using API, I downloaded the last three posts and everything works as it should.
However, is it possible for three other posts to be drawn after each code generation?
He tries to grasp it with:
'post_type' => 'post', 'orderby' => 'rand',
However, they do not work. Could someone have met with such a case?
My code below:
<?php
$a=array("http://site.pl/wp-json/wp/v2/posts/","http://site.pl/wp-json/wp/v2/posts/?order=asc&orderby=id");
$random_keys=array_rand($a,2);
echo $a[$random_keys[0]];
require_once( '../wordpress/wp-load.php' );
$response = wp_remote_get( add_query_arg( array(
'per_page' => 3,
'orderby' => 'title',
'order' => 'asc',
), $a[$random_keys[0]] ) );
if( !is_wp_error( $response ) && $response['response']['code'] == 200 ) {
$remote_posts = json_decode( $response['body'] ); // our posts are here
foreach( $remote_posts as $remote_post ) {
// display post titles and excerpts
echo '<h2>'. $remote_post->title->rendered . '</h2><p>' . $remote_post->excerpt->rendered . '</p>';
// need more parameters? print_r( $remote_post )
}
}
?>