WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to get a specific Gallery ID inserted to a post in wordpress 3.5? I want to load gallery from post using Ajax. I use shortcode [gallery] to do it. But when I use it this way:

echo do_shortcode('[gallery id="'.$_POST['postid'].'"]');

I get all images attached to the post with $_POST['postid'] and not images from the gallery which is inserted to that post.

share|improve this question
The second one helped me, thank you. – Paul Jan 15 '13 at 12:18

In single.php i put this code, from this link (thank you Wyck) http://stackoverflow.com/questions/14277794/wordpress-3-5-own-gallery-with-included-images-doesnt-work

preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids);
$array_id = explode(",", $ids[1]);

Now I can use gallery shortcode [gallery ids=" id's from $array_id here "]

share|improve this answer

The plain, old [gallery] should still work here.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.