The problem is that your code creates a post if the created post is not manually-published, but the new post is automatically-published, and those don’t match. Your conditional is not explicit enough and eneds to skip the scenario when your inserted post is inserted to prevent an infinite loop
Instead of:
function create_auto_post($post_ID) {
if (get_post_type($post_ID) != 'manually-published') return;
Consider:
function create_auto_post( $post_ID, $post ) {
if ( in_array( $post->post_type, [ 'manually-published', 'automatically-published' ] ) {
return;
}
Further notes:
- This isn’t a filter it’s actually an action, use
add_actioninstead - The
save_postaction passes the post object as a second parameter, it’s better to use that - You’ll need to indicate that this function takes 2 not 1 parameter for this to work
- Your original code assumes all posts will be of 2 post types, but you forget that images/attachments are also a post type, as are menu items in nav menus, and many other things that other plugins add. Right now it’s going to create
automatically-publishedposts for all your menu items and attachments, as well as other things you might not have considered