Created
June 8, 2016 19:55
-
-
Save rbk/225b97e3870d1adc4dbb37018d16cfbf to your computer and use it in GitHub Desktop.
Query WordPress and add the metadata to the result.
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 | |
/* | |
* | |
* Get posts with a standard query | |
* Include all the meta data in the result | |
* | |
*/ | |
function get_posts_with_meta( $args ) { | |
$query = get_posts($args); | |
for($i=0;$i<count($query);$i++) { | |
$meta = get_post_meta( $query[$i]->ID ); | |
foreach( $meta as $key => $value ) { | |
$query[$i]->{$key} = $value[0]; | |
} | |
} | |
return $query; | |
} | |
$args = array( | |
'post_type' => 'page', | |
'posts_per_page' => -1 | |
); | |
$query = get_posts_with_meta( $args ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment