Question

I'm trying to automatically create a new post when a post containing a certain custom field is saved - hooking an insert_post function into save_post.

This generates an infinite loop.

I found some answers to this problem, suggesting I should check the post type before inserting.

However, the following code still gives an infinite loop, any ideas?

add_action('save_post', 'createGallery');

function createGallery () {
    global $post;
    if ( $post->post_type == 'activity' ) {
        $gallerypost = array(
            'post_content' => 'the text of the post',
            'post_status' => 'publish', 
            'post_title' => 'Photo album', 
            'post_type' => 'post', 
            'post_author' => 1);  
        wp_insert_post( $gallerypost );
    }
}

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top