Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9037683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:18:10+00:00 2026-06-16T09:18:10+00:00

I’ve been playing around with the new media manager in WordPress and had some

  • 0

I’ve been playing around with the new media manager in WordPress and had some fun with it, but have reached the point where I’m banging my head against a wall.

I have a custom meta box that I’d like to store some images in (well it’s a hidden input and I’m currently storing their ID’s, but could equally be the image objects), then making an AJAX call to show some thumbnails, which I have subsequently made draggable so users can reorder (not necessarily relevant just some background).

My problem is that when I open the media manager, no images are selected, so if a user wants to edit the pictures in their gallery they need to select them all again.

What I’m trying to figure out, is how do I open the media manager with the current images passed through so they are pre-selected.

So, broadly, my code looks like this

jQuery('#myButton').click(function(e) {
  e.preventDefault();
  frame = wp.media({
    title : 'My Gallery Title',
    multiple : true,
    library : { type : 'image'},
    button : { text : 'Insert' },
  });
  frame.on('close',function() {
    // get selections and save to hidden input plus other AJAX stuff etc.
  }
  frame.open();
});

My thought is that there must be either a parameter to pass into the frame (probably a JSON object of the images, or I need to create an event for

frame.on('open', function() {
  // Set selected images
}

But I have tried both ways round and am not getting anywhere.

It would appear possible, as changing the ‘Featured Image’ takes you to the library with the current one selected – I’ve just been unable to understand the core code sufficiently yet and hope someone else has !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:18:12+00:00Added an answer on June 16, 2026 at 9:18 am

    After studying the core for a bit, the answer here is really quite straightforward.

    Listen for the open event of the wp.media object, grab the state, create attachment objects with your id’s and add them to the selection.

    frame.on('open',function() {
      var selection = frame.state().get('selection');
      var ids_value = jQuery('#my_field_id').val();
    
      if(ids_value.length > 0) {
        var ids = ids_value.split(',');
    
        ids.forEach(function(id) {
          attachment = wp.media.attachment(id);
          attachment.fetch();
          selection.add(attachment ? [attachment] : []);
        });
      }
    });
    

    This works when selecting multiple images as well as single and assumes that using the code above you have stored the values in a single text/hidden field with comma separation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have been unable to fix a problem with Java Unicode and encoding. The
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.