Snippets repository for WordPress developpers

Browse
// into pages or template files
<?php 
$args = array(
  'post_type' => 'name-of-the-custom_post_type', // Name of the CPT
  'posts_per_page' => 3, // Number of post to display
  'order' => 'DESC', // ASC ou DESC 
  'orderby' => 'date', // title, date, comment_count...
);

$my_query = new WP_Query( $args );
if( $my_query->have_posts() ) : while( $my_query->have_posts() ) : $my_query->the_post();
  the_title();
  the_content();
  // ...
endwhile;
endif;

wp_reset_postdata(); // important!
?>

Warning: Trying to access array offset on null in /home/clients/7f7a8d8eb6e40c50d3548b06c548734d/web/wp-includes/class-wp-query.php on line 3766

Categories

Tags