Home Forums Add-ons Gallery Field Custom JS Interferes with Gallery Field


Custom JS Interferes with Gallery Field

  • So I have a slight issue. For every post, in every post type, ever I have a function which only displays media uploaded to that post. It looks like this:

     * Media Module - Only Show Images Uploaded To <code>$this</code> Post
     * @return void
    function theme_media_library_filter() { 
    	  <script type="text/javascript">
    		jQuery( document ).on( 'DOMNodeInserted', function() {
    			jQuery( 'select.attachment-filters [value="uploaded"]' ).attr( 'selected', true ).parent().trigger( 'change' );
    		} );
    add_action( 'admin_footer-post-new.php', 'theme_media_library_filter' );
    add_action( 'admin_footer-post.php', 	 'theme_media_library_filter' );

    The problem is whenever I’m using a field such as The Gallery field, ( if I drop / drop media it works fine ) and go to the Upload tab, upload media, the media does not show up until after I close the window and open it back up. I do know that the field does have the option to only show media uploaded to this post but the problem is that I think my code that works for all other posts interferes with this functionality and I’m looking for a workaround.

    My thoughts are this, find a way to ignore my JS whenever the ACF media module is open or find a way to have my code work with ACF so that they both place nicely. Any ideas how I can achieve this?

Viewing 1 post (of 1 total)

The topic ‘Custom JS Interferes with Gallery Field’ is closed to new replies.