How to create a WordPress custom loop. Useful when needing to query specific data.
First we need to declare the arguments for the loop. Here is a full list of all the possible arguments from Bill Erickson.
$args = array(
'posts_per_page' => get_option('posts_per_page'),
'post_type' => 'project', // <-- the name of your custom post type
'post_status' => 'published'
);
Next we loop through the posts that we want to show based on the arguments we declared above.
<?php
$query = new WP_Query($args);
if ( $query->have_posts() ) :
while ($query->have_posts()) : $query->the_post(); ?>
<?php get_template_part('inc/card-content'); ?>
<?php endwhile; ?>
<?php else : ?>
<p>Sorry, there are no projects to show at this time.</p>
<?php endif; wp_reset_postdata(); ?>
Make sure to add wp_reset_postdata(); right after the last if statement to return the $post global to the current post in the main query.
<input type="text" name="email" disabled="disabled" />
<input type='text' name='email' disabled='disabled' />