• Resolved hshah

    (@hshah)


    I have a form which uses a Gallery field and the Media Library to allow users to create photo albums on my site.

    If I follow:
    Edit > Add to Gallery > Upload Files > [upload image]

    Then close the Media Library window (without pressing “Select”), which would leave me with the Edit form. The Gallery field there still shows the original images, and not the one I just uploaded.

    If I think close that form by using the x in the top corner, and not the Submit button, I would have effectively “cancelled” what I was doing.

    However, if I refresh the post, the photo I uploaded but did not Select or Submit, is present in the post gallery. If I open the Edit form again, the Gallery field there still shows the original images, whereas the post has additional content.

    Any ideas anyone?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter hshah

    (@hshah)

    Screenshots after having twice done what I mentioned above (hence the 3 and 5):

    View post on imgur.com

    View post on imgur.com

    I have a ‘acf/save_post’ function to set the attachment post_parent reference, so to rule that out, I added some logging… that function was definitely not invoked.

    Can’t work out how the upload as ended up in that post. I’ve tried searching for this issue, but I’ve only found issues of attaching to posts, not images being attached randomly. 🙁

    • This reply was modified 6 years ago by hshah.
    Thread Starter hshah

    (@hshah)

    Ahh… I think this is WordPress functionality at play here. Uploading media from a post automatically attaches it.

    Looks like I need to find a way of stopping it doing that!

    Thread Starter hshah

    (@hshah)

    Not sure if this is the best way of sorting this, but here is what I have done and it seems to be working:

    add_filter('add_attachment', 'disable_automatic_post_upload_attachment', 10, 1);
    function disable_automatic_post_upload_attachment($attachment_id) {
    	// Uploading to Existing Post
    	if ($_POST['action'] == 'upload-attachment' && $_POST['post_id'] != 0 )  {
    		// Check for CPT
    		if ( get_post_type($_POST['post_id']) == 'photos' ) {
    			// Force post_parent to 0
    			wp_update_post( array( 'ID' => $attachment_id, 'post_parent' => 0 ) );
    		}
    	}
    }
    Thread Starter hshah

    (@hshah)

    Marking this as resolved because my “issue” was down to core WordPress functionality rather than related to this plugin.

    My “fix” (mentioned in the previous post) has been working fine, so people are welcome to use it. If anyone has any better suggestions, please let me know 🙂

    Plugin Author Shabti Kaplan

    (@shabti)

    @hshah thank you for the code snippet! I appreciate all of your help in resolving issues people have

    Thread Starter hshah

    (@hshah)

    Happy to help 🙂

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Uploading to Gallery – Strange Behaviour’ is closed to new replies.