Loop – I want to dynamically load posts in bootstrap modal

Is it on single page template, archive page template, single post template? Where should this code be in relation to the main question? It’s hard to provide advice or solutions without the context of what you’re trying to achieve.

If you’re trying to create a section on a page template that pulls in your posts in addition to the page’s content, this will require you to create a secondary query to pull in those posts.

If what I described is what you are trying to do: https://developer.wordpress.org/reference/classes/wp_query/

Basically, you would do a new query outside of your main query (aka where the page content is coming from) A simple example is below. Several additional parameters are available to refine the query.

$newArgs = array(
    'post_type' => 'post',
$query = new WP_Query( $newArgs );

Then run a second loop and put your modal code in it, it looks like you’re also using ACF which should be fine. A basic example is below:

if ( $newArgs->have_posts() ) {
    while ( $newArgs->have_posts() ) {
        // Modal code here
    } // end while
} // end if

More information about the loop here: https://codex.wordpress.org/The_Loop

Leave a Comment