I'm trying to create a page after creating a Woocommerce product so i need to use wp_insert_page()
function.
When creating a product, a page is created just fine but post_content
is getting filtered.
$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 );
}
This is the code i'm running. When the page is created in the page content is showing the text Start End
, which means is filtering the $post->post_content
out of the content.
I have already tried some of suggestions i found in other threads like:
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');
which i found in https://wordpress.stackexchange.com/a/75582/168054
and
remove_all_filters("content_save_pre");
$created_page = wp_insert_post( $page );
which i found in https://stackoverflow.com/a/21983728/9443416, but neither of them removed the filters.
Any help is appreciated.