Answers for "wordpress query recent posts"

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
-1

wordpress popular posts query

$popularpost  = new WP_Query(array(
    'posts_per_page' => 5,
    'meta_key' => 'wpb_post_views_count',
    'orderby' => 'meta_value_num',
    'order' => 'DESC'
));
Posted by: Guest on June-07-2021

Browse Popular Code Answers by Language