Show a load of WordPress posts using get_posts()

4 years ago

rosswintle

Open this in a WordPress project and you can quickly get a list of posts displayed in table view! Amazing!

Code

function postToArray($post) {
  return $post->to_array();
}

array_map('postToArray', get_posts([
  	'post_type'      => 'post',
    'posts_per_page' => '25',
	// Stick some get_posts parameters here!  
]));
Video course: PHP Package Development