Answers for "query post 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
0

wp_query to get posts

<?php 
$args = array( 
	'post_type'   => 'post',
	'post_status' => 'future'
);
$scheduled = new WP_Query( $args );

if ( $scheduled->have_posts() ) : 
?>
	<?php while( $scheduled->have_posts() ) : $scheduled->the_post() ?>
		<!-- Display Post Here -->
	<?php endwhile ?>
<?php else : ?>
	<!-- Content If No Posts -->
<?php endif ?>
Posted by: Guest on November-02-2020
0

the post function wordpress

if ( have_posts() ) {
    while ( have_posts() ) {
 
        the_post(); ?>
 
        <h2><?php the_title(); ?></h2>
 
        <?php the_content(); ?>
 
    <?php }
}
Posted by: Guest on August-17-2021

Code answers related to "query post wordpress"

Browse Popular Code Answers by Language