WP_query

918

Last updated

Added

Informations

This code allow you to get posts from the post type or custom post type you choose with parameters.

Code

<?php
$args = array(
  ‘post_type’ => ‘post_type_slug’,
  ‘posts_per_page’ => -1,
  ‘orderby’ => ‘date’,
  ‘order’ => ‘DESC’,
);
?>

 

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

 

<?php if($the_query->have_posts()) : ?>
  <?php while($the_query->have_posts()) : $the_query->the_post(); ?>

 

    <?php the_title(); ?>
 
  <?php endwhile; ?>
<?php endif; ?>

 

<?php wp_reset_query(); ?>
<?php wp_reset_postdata(); ?>

Contribute to this page

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *


'post_type_slug', 'posts_per_page' => -1, 'orderby' => 'date', 'order' => 'DESC', ); ?> have_posts()) : ?> have_posts()) : $the_query->the_post(); ?>