只需使用template\\u redirect filter对您在wordpress中得到的请求执行检查。
add_filter(\'template_redirect\', \'my_404_override\' );
function my_404_override() {
global $wp_query;
if (!$wp_query->post) { // Check if any post is found. If not its 404.
status_header( 200 );
$wp_query->is_404=false;
// Create post object
$my_post = array(
\'post_title\' => \'My post\',
\'post_content\' => \'This is my post.\',
\'post_status\' => \'publish\',
\'post_author\' => 1,
\'post_category\' => array(8,39)
);
// Insert the post into the database
$post_id = wp_insert_post( $my_post ); // Add new post in to the system
wp_redirect( get_permalink( $post_id ) ); // Finally redirect it to the post.
}
}
这将为您创建一个新帖子(&;也会将用户重定向到该帖子。嗯,坦率地说,这是一个完成任务的补丁,但它达到了目的。