如果你在single_{$post_type_slug}
样板您可以这样做:
// Create an array with the name of all custom field
$custom_field_names = array( \'custom_field1\', \'custom_field2\' );
$custom_fields;
$args = array (
\'post_type\' => \'post\',
\'posts_per_page\' => -1
);
$posts = get_posts( $args );
// Get all the custom fields for this post
foreach( $posts as $key => $post ) {
foreach( $custom_fields_names as $name ) {
$custom_fields[$key][$name] = get_field( $name, $post->ID )
}
}