create new page first time a new post is saved
-
Hi,
As the tile suggests i want to create a new page after saving a new post for the first time. Its the standard Post type, not a custom post type. However its important that the post should have a specific ‘category’ so we only do this for posts of this post category. Heres some code I’ve got so far in my functions.php file :function create_newpage_for_newpost( $post_id, $post, $update ) { // Only want to set if this is a new post! if ( $update ){ return; } // Only set for post_type = post! if ( 'post' !== $post->post_type ) { return; } // Create new page based on this new post - New page should : // 1. Use a pre-built elementor page-template // 2. Use the post name (from post_id) in naming the new page. // 3. pre populate some ACF fields with data from the post (advanced, so i'll find a method to do this myself) $newpage_title = get_the_title( $post_id ) . ' - history log'; $link_back_to_post = get_permalink( $post_id ); } add_action( 'save_post', 'create_newpage_for_newpost', 10,3 );
Its important that we only create one page per new post so we need to ignore ‘save to draft’ and other post statuses. The new page also should be based on a pre-saved Elementor page template (see comments in code above).
Thanks
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘create new page first time a new post is saved’ is closed to new replies.