Skip to content

Instantly share code, notes, and snippets.

@will83
Created April 3, 2015 17:03
Show Gist options
  • Save will83/3ebc304627568984fff1 to your computer and use it in GitHub Desktop.
Save will83/3ebc304627568984fff1 to your computer and use it in GitHub Desktop.
Function to get all custom fields within the $post global
<?php
function get_all_post_custom_fields( $posts ) {
for ( $i = 0; $i < count($posts); $i++ ) {
$custom_fields = get_post_custom( $posts[$i]->ID );
$posts[$i]->custom_fields = $custom_fields;
}
return $posts;
}
add_filter( 'the_posts', 'get_all_post_custom_fields' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment