phpwordpress

wordpress custom post types last four


I create my custom post type in wordpress to create a portfolio, then in the home page I want this script to show my last four clients

                    <!-- INIZIO LOOP PER L'ESTRAZIONE E RICHIAMO DATI PORTFOLIO-->
                <?php

                    //Array di configurazione Loop
                    $args = array(
                        'post_type' => 'portfolio',
                        'post_per_page' => 4
                    );
                    $nuovo_loop = new WP_Query( $args );
                        if( $nuovo_loop->have_posts() ) :
                        while( $nuovo_loop->have_posts() ) : $nuovo_loop->the_post();
                ?>

                <!-- Cosa fare dentro il loop -->
                <div class="grid_3 portElements">

                    <div class="full_overlay">
                        <div class="content">
                            <span class="portfolioimage">
                                <p><?php the_title(); ?></p>
                                <a href="<?php the_permalink(); ?>" target="_self">
                                    <span class="DWSdetails">dettagli</span>
                                </a>
                                <a href="<?php
  $myExcerpt = get_the_excerpt();
  $tags = array("<p>", "</p>");
  $myExcerpt = str_replace($tags, "", $myExcerpt);
  echo $myExcerpt;
  ?>" id="outLink" target="_blank">
                                    <span class="view">visita </span>
                                </a>

                            </span>
                        </div>
                        <div class="portImage" >
                             <?php if ( has_post_thumbnail() ) {
                                        the_post_thumbnail('thumbImage');
                                    }else{
                                        echo '<img src="http://www.dywes.com/wp-content/themes/dywes/images/workinprogress.png" />';
                                    }
                            ?>
                        </div>

                    </div>
                </div>
                <?php
                    endwhile;
                    else:
                ?>  
                <!-- Cosa fare se il loop non trova niente -->
                <?php 
                    endif;
                    wp_reset_postdata();
                ?>


            </div>
                <!--FINE LOOP PORTFOLIO-->

But when I reload the page I see all my clients... How can I get to see just 4 of it?


Solution

  • $args = array(
                        'post_type' => 'portfolio',
                        'posts_per_page' => 4,
                        'order' => 'DESC',
                        'orderby' => 'post_date'
                    );
    

    This should show last 4. More details you can find in Codex