1. Home
  2. Wordpress
  3. Custom posts loop

Pass arguments to WP_Query with a tag of a custom post.

#wordpress#php
<?php // args
        $args = array(
        'post_type' => 'custom-post',
        'order' => 'ASC',
        'posts_per_page' => -1 // Get all posts
        );

        $the_query = new WP_Query( $args );
?>

<?php if( $the_query->have_posts() ): ?>
        <?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
                <a href="<?php the_permalink();?>"><?php the_title(); ?></a>
        <?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); // Reset loop ?>
copy
Full Wordpress cheatsheet
NordVPN NordVPN