Query any Post Type anywhere


/ Published in: PHP
Save to your folder(s)

Query any Post Type anywhere


Copy this code and paste it in your HTML
  1. //when 'blog' is the custom post type
  2. <?php $args = array( 'post_type' => 'blog', 'posts_per_page' => 1);
  3. $loop = new WP_Query( $args ); ?>
  4. <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
  5. <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  6. <?php endwhile; ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.