Last active
July 6, 2023 10:42
-
-
Save ann71727/ced5903bf3427dbbc0ba435768e163d3 to your computer and use it in GitHub Desktop.
WordPress WP_Query() result posts object to an array
This file contains 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
<?php | |
/* | |
* Convert Object To Array | |
* https://v123.tw | |
*/ | |
$args = array( | |
'showposts' => -1, | |
'post_type' => 'post', | |
'post_status' => 'publish' | |
); | |
$result = new WP_Query($args); | |
$data = array_map( | |
function( $post ) { | |
return (array) $post; | |
}, | |
$result->posts | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment