要修改帖子的内容,可以使用the_content
滤器您(可能)只想将post meta添加到主查询中。如果没有,可以跳过is_main_query()
有条件的然后,您可以获取帖子元并按照您认为合适的方式对其进行格式化,然后将其附加到内容中。
//* Add filter to the_content if we\'re in the main query
add_action( \'the_post\', \'wpse_261935_the_post\' );
function wpse_261935_the_post( $post ) {
if( is_main_query() ) {
add_filter( \'the_content\', \'wpse_261935_the_content\' );
}
}
function wpse_261935_the_content( $content ) {
//* Make sure to add and remove filter for each post
//* to make sure it\'s in the main query
remove_filter( \'the_content\', \'wpse_261935_the_content\' );
$wpse_261935_meta = get_post_meta( get_post()->ID, \'_wpse_261935_post_meta_key\', true );
$wpse_261935_content = wpse_261935_format_post_meta( $wpse_261935_meta );
return $wpse_261935_content . $content;
}
function wpse_261935_format_post_meta( $post_meta ) {
//* Format the post meta however you\'d like
return $html;
}