Answers for "get posts with recent posts in wordpress"

PHP
1

recent post query wordpress

<?php 
            $recent_args = array(
                'post_type' => 'post type name',
                'posts_per_page' => 4,
                'orderby'        => 'date',
                'order'          => 'DESC'
            );      
            $recent_posts = new WP_Query( $recent_args );
            
            if( $recent_posts->have_posts() ) {
        	    while( $recent_posts->have_posts() ) : $recent_posts->the_post(); 
                
                the_title();
                
                endwhile;
            
    		} 
    		else {
    	    	echo "There is no posts";
    	    }
    
    	    wp_reset_postdata();   
 ?>
Posted by: Guest on June-07-2021

Browse Popular Code Answers by Language