So, calling this PHP from click through ajax I manage to display Title and content in my modal. But when the code gets to get_post_gallery it always returns null.

$the_query  = new WP_Query(array('p' => $pid));

if ($the_query->have_posts()) {
    while ( $the_query->have_posts() ) {
        $data = '
        <div class="post-container">
            <div id="project-content">
                <h1 class="entry-title">' . get_the_title() . '</h1>
                <div class="entry-content">' . get_the_content() . '</div>


        if ( get_post_gallery( ) ) :
                $gallery = get_post_gallery(get_the_ID(), false );              

On a side note, the method works on a single.php page. So I assume it's a problem of context. Thanks for your help.

  • You will return an array try to print r the $gallery. – Tejas Gajjar Jan 30 '19 at 10:50

Have you tried passing $pid instead of using get_the_ID()?

if (get_post_gallery($pid)) :
   $gallery = get_post_gallery($pid, false);
  • yup, I tried that too. – Antoine Jan 30 '19 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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