$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>images - Get gallery in loop through ajax|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

images - Get gallery in loop through ajax

matteradmin8PV0评论

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() ) {
        $the_query->the_post();
        $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>

            </div>
        </div>  
        ';

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

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.

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() ) {
        $the_query->the_post();
        $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>

            </div>
        </div>  
        ';

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

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.

Share Improve this question edited Jan 30, 2019 at 10:22 Pratik Patel 1,1091 gold badge11 silver badges23 bronze badges asked Jan 30, 2019 at 10:13 AntoineAntoine 12 bronze badges 1
  • You will return an array try to print r the $gallery. – Tejas Gajjar Commented Jan 30, 2019 at 10:50
Add a comment  | 

1 Answer 1

Reset to default 0

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

if (get_post_gallery($pid)) :
   $gallery = get_post_gallery($pid, false);
endif;

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far