O-ded
O-ded

Reputation: 57

WordPress archive page "no posts" addion

My code:

<?php
$today = date('d/m/Y');
$the_query = new WP_Query( array( 'post_type' => 'show', 'meta_key' => 'date', 'meta_value' => ''.$today.'' ) ); 

// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post(); 
require('post.php');
endwhile;

// Reset Post Data
wp_reset_postdata();
?>

How can I add "Theres no posts" when have posts = 0?

Upvotes: 0

Views: 29

Answers (1)

Mani Khan
Mani Khan

Reputation: 61

just ad if and else conditions

    <?php 
    if ($the_query->have_posts()) :
    while ( $the_query->have_posts() ) : $the_query->the_post();

    // you contents goes here

    endwhile;


    else :

    echo "<h2>There is no post</h2>";

    endif; ?>

Upvotes: 1

Related Questions