Answers for "get_posts custom post type"

PHP
1

wp_query get custom post type

<?php    
  	   $args = array(  
      'post_type' => 'custom_type',
      'post_status' => 'publish',
      'posts_per_page' => 8, 
      'orderby' => 'title', 
      'order' => 'ASC', 
          );

  $loop = new WP_Query( $args ); 

  while ( $loop->have_posts() ) : $loop->the_post(); 
      print the_title(); 
      the_excerpt(); 
  endwhile;

  wp_reset_postdata(); 
  ?>
Posted by: Guest on November-27-2020
0

pre_get_posts custom post type archive

<?php
function wpmark_alter_team_archive_template_query( $query ) {
    
    /* only proceed on the front end */
    if( is_admin() ) {
	    return;
    }
    
    /* only on the person post archive for the main query */
    if ( $query->is_post_type_archive( 'wpmark_person' ) && $query->is_main_query() ) {
	    
        $query->set( 'posts_per_page', -1 );
        
    }
    
}

add_action( 'pre_get_posts', 'wpmark_alter_team_archive_template_query' );
?>
Posted by: Guest on September-18-2020

Browse Popular Code Answers by Language