Created
November 18, 2019 02:01
-
-
Save redsoxfan2499/f58931c444ad6de95dd43d0b4b67f6cc to your computer and use it in GitHub Desktop.
WordPress Get Custom Fields / ACF Fields to be included in custom WP Query
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
/** Place this in themes functions.php file **/ | |
function my_always_get_post_custom( $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', 'my_always_get_post_custom' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment