我正在尝试在创建Woocommerce产品之后创建页面,因此我需要使用wp_insert_page()
函数。
创建产品时,页面创建得很好,但是post_content
正在被过滤。
$permalink = $post->post_title .'-landing-page';
$content = 'Start ' .$post->post_content. ' End';
$page = array(
'post_title' => $post->post_title,
'post_name' => $permalink,
'post_content' => $content,
'post_status' => 'publish',
'post_author' => $post->post_author,
'post_type' => 'page',
);
$page_exists = get_page_by_title( $page['post_title'] );
if( $page_exists == null ) {
$created_page = wp_insert_post( $page );
}
这是我正在运行的代码。在页面中创建页面后,内容将显示文本Start End
,这意味着正在从内容中过滤$post->post_content
。
我已经尝试了在其他线程中发现的一些建议,例如:
remove_filter('content_save_pre', 'wp_filter_post_kses');
remove_filter('content_filtered_save_pre', 'wp_filter_post_kses');
$created_page = wp_insert_post( $page );
add_filter('content_save_pre', 'wp_filter_post_kses');
add_filter('content_filtered_save_pre', 'wp_filter_post_kses');
我在https://wordpress.stackexchange.com/a/75582/168054中找到的
和
remove_all_filters("content_save_pre");
$created_page = wp_insert_post( $page );
我在https://stackoverflow.com/a/21983728/9443416中找到的,但是他们都没有删除过滤器。
感谢您的帮助。