我找到的最初解决方案是将过滤器绑定到如下操作上wp_insert_post_data 并从全球$post 对象
// Tack our filter onto the wp_insert_post_data action
add_filter( \'wp_insert_post_data\', \'my_appender\' );
function my_appender( $content ) {
// Bring global $post into scope
global $post;
// Get meta value of meta key \'key_name\'
$meta_value = get_post_meta( $post->ID, \'key_name\', TRUE );
// If value is not in content, append it onto the end
if ( stristr( $content[\'post_content\'], $meta_value ) === FALSE )
$content[\'post_content\'] .= $meta_value;
// Return filtered content
return $content;
}
我相信这会有所改善。
References
add_filter() - “过滤器是WordPress启动的挂钩…”wp_insert_post_data - “wp\\u insert\\u post函数调用的筛选器挂钩…”global keyword - “变量的范围是定义它的上下文…”get_post_meta() - “此函数返回自定义字段的值…”stristr() - “查找字符串的第一个匹配项(不区分大小写)