Answers for "wp_query find post by post_type"

PHP
5

wordpres get_posttype

if ( get_post_type( get_the_ID() ) == 'slug_post_type' ) {
    //if is true
}
Posted by: Guest on June-17-2020
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
1

wordpress get post type

// Retrieves the post type of the current post or of a given post.
get_post_type( int|WP_Post|null $post = null )
Posted by: Guest on February-19-2021

Browse Popular Code Answers by Language