• Resolved jeffmikels

    (@jeffmikels)


    When using wp_insert_attachment to programmatically add an attachment to a post, the post type of the attachment gets changed from attachment to whatever the post type of the parent was. This causes the attachment to disappear from the wordpress interface entirely, but leaves it on the filesystem.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter jeffmikels

    (@jeffmikels)

    I can fix it by making sure my save_post hook runs after the post type switcher’s hook.

    Hi, I have same report about it.

    With plugin Advanced Custom Fields is same bug. If I have “file” field for example on page post type, my attachment was changed to “page”. So it is annoying bug!

    In acf is function, which change post_parent of attachment to content (in my example tp “page”). It is called like that

    wp_update_post( array(‘ID’ => $post->ID, ‘post_parent’ => $post_id ) );

    Well, what im investigated

    in your plugin is
    add_filter( ‘wp_insert_post_data’, array( $this, ‘override_type’ ), 10, 2 );

    there should be something similar

    if ( $_GET[“post”] !== $data[‘ID’] )
    return $data;

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Post Type incorrectly set when adding attachments programmatically’ is closed to new replies.