Answers for "wordpress query post"

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
0

wordpress query a post by id

//WordPress: Query a specific post by its post type & ID
//For example, query Case Study with ID #12345

<?php query_posts('post_type=case_studies&p=12345'); ?>
  
/*To determine a post ID, refer to the
URL of the post while editing it:
http://localhost...wp-admin/post.php?post=12345...*/
Posted by: Guest on January-14-2020

Code answers related to "wordpress query post"

Browse Popular Code Answers by Language