Example 1: get post by category

<section class="films-tabs pd-40" id="portfolio">

   $film_genres = get_terms('portfolio_cat'); // get all the genres ?>

<div class="container">
<div class="row">
  
  <ul class="nav nav-tabs nav-justified">
     foreach($film_genres as $film_genre) { ?>
      <li>
        <a href="# echo $film_genre->slug ?>" data-toggle="tab"> echo $film_genre->name ?>a>
      li>
     } ?>
  ul>
div>
div>

  
  <div class="tab-content">

     foreach($film_genres as $film_genre) { ?>

      <div class="tab-pane" id=" echo $film_genre->slug ?>">
         	
        $args = array(
          'post_type' => 'portfolio',
          'showposts' => -1,
          'orderby' => 'title',
          'order' => 'ASC',
          'tax_query' => array(
            array(
              'taxonomy' => 'portfolio_cat',
              'field' => 'slug',
              'terms' => $film_genre->slug
            )
          )
        );
        $films = new WP_Query( $args );		
        ?>

         if ( $films->have_posts() ) : // make sure we have films to show before doing anything?>
        <div class="table">
            <div class="container">
                <div class="row">
                   while ( $films->have_posts() ) : $films->the_post(); ?>	
                  
                    <div class="table-cont"><a data-fancybox="gallery" href=" echo get_the_post_thumbnail_url();?>".> the_post_thumbnail() ?>a>div>
                  
                   endwhile; ?>
                   wp_reset_query() ?>
                 div>
            div>
        div>
         endif; ?>

      div>
     }  ?>

  div>

section>

Example 2: wordpress get 10 posts of each custom post type

function delete_front_page_query_results() {
    delete_transient('post_data');

    $query_cpt1 = array (
            'posts_per_page'   => 3,
            'post_type' => 'cpt1'
            );
    $query_cpt2 = array (
            'posts_per_page'   => 3,
            'post_type' => 'cpt2'
            );
    $query_cpt3 = array (
            'posts_per_page'   => 3,
            'post_type' => 'cpt3'
            );
    $query_cpt4 = array (
            'posts_per_page'   => 3,
            'post_type' => 'cpt4'
            );
    $query_cpt5 = array (
            'posts_per_page'   => 3,
            'post_type' => 'cpt5'
            );

    $query_results[] = get_posts($query_cpt1);
    $query_results[] = get_posts($query_cpt2);
    $query_results[] = get_posts($query_cpt3);
    $query_results[] = get_posts($query_cpt4);
    $query_results[] = get_posts($query_cpt5);

    //flattening three dimentional array to two dimensonal array
    $flatten_array =array();
    foreach ($query_results as $data) {
            foreach($data as $flatten_data) {
                 $flatten_array[] = $flatten_data;
            }
    }

    function cpt_array_sort($a, $b) {
            return strtotime($b->post_date) - strtotime($a->post_date);
    }
    usort($flatten_array, 'cpt_array_sort');

    //setting transient with the array
    set_transient ( 'post_data', $flatten_array, 365*24*60*60);
}
add_action('publish_post', 'delete_front_page_query_results);