WP_Query,
Going Beyond The Loop

https://joseph-dickson.com/presentation/wp-query-the-loop

Use your arrow keys or swipe to navigate this slideshow

Joseph Dickson

The Loop

Screenshot of a Hello world! post on a WordPress website.
Hello world!
Reading Settings in the WordPress Dashboard
<?php 
if ( have_posts() ) {
	while ( have_posts() ) {
		the_post(); 
		
		// Post Content here
		
	} // end while
} // end if
?>

The Loop is Simple, Predictable,
and Reliable

WP_Query

Screenshot of a WP_Query example from WordPress.org
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
   while ( $the_query->have_posts() ) {
       $the_query->the_post();
       echo '<li>' . get_the_title() . '</li>';
   }
echo '</ul>';
} else {
    // no posts found
    echo 'no posts found.';
}
/* Restore original Post Data */
wp_reset_postdata();
Screenshot of a WP_Query example from WordPress.org

Assigning Argument Parameters

// The Query
$the_query = new WP_Query( $args );
$the_query = new WP_Query(
  array('post_type' => 'page' )
);

// The Query
$the_query = new WP_Query( $args );
$the_query = new WP_Query(
  array('post_type' => 'attachment' )
);

// The Query
$the_query = new WP_Query( $args );
$the_query = new WP_Query(
  array(
    'post_type' => 'attachment',
    'post_mime_type' => 'application/pdf',
    'posts_per_page' => '-1,
  )
);

// The Query
$the_query = new WP_Query( $args );

Creating Practical Design Solutions with WP_Query

Dynamic & Conditional Content

Sceenshot of Author Bio
screenshot of code that checks the post author meta
screenshot code that displays the author content

How about Displaying another unique message?

template-parts/wp-query-home.php
front-page.php
The Result on My Website’s Homepage.

Complex But Practical Uses for WP_Query

Use WP_Query to Displaying Information from Plugins

WP_Query & Custom Post Types

Joseph Dickson

https://joseph-dickson.com/presentation/wp-query-the-loop