Custom post type query with taxonomy

Question

I use this query to call posts from a custom-type post I setup apart

$args = array( 'posts_per_page' => 5, 'order'=> 'DES', 'post_type' => 'custom-post' );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<div class="thumbnail">
<?php echo get_the_post_thumbnail( $post->ID, 'thumbnail' ); ?>
</div>
<?php the_title( sprintf( '<h2><a href="%s">', esc_url( get_permalink() ) ),'</a></h2>' ); ?>
<?php  echo '<p>' . get_the_excerpt() . '</p>' ?>
<?php endforeach;
wp_reset_postdata();

Two questions:

  1. Is that correct or can I improve it better somehow?
  2. Is it possible to call posts that are placed both in 2 different taxonomy generated from that custom post type (“flowers” and “colors” for instance) and then call post that is in the “flowers” category but not in the “colors” one?

Thank you

0
PaoloPgn 4 months 0 Answers 17 views 0

Leave an answer