Answers for "wp_query post type category"

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

post type category name in query

$args = array(
        	'post_type' => 'post',
        	'posts_per_page' => 4
        );
        $query = new WP_Query( $args );

	     if( $query->have_posts() ) {
    	    while( $query->have_posts() ) : $query->the_post(); 
                foreach((get_the_category()) as $category) { 
                  echo $category->cat_name . ' '; 
                } 
        endwhile;
		} 
		else {
	    	echo "There is no posts";
	    }

	    wp_reset_postdata();   ?>
Posted by: Guest on June-07-2021
0

wp_query custom post type

//WordPress: Query a custom post type
//For example, query all Case Study post types

<?php query_posts('post_type=case_studies'); ?>
Posted by: Guest on January-14-2020

Code answers related to "wp_query post type category"

Browse Popular Code Answers by Language