• Hello everyone,

    Ive got a wordpress site up and running. An overview of whats happening:

    ive got the upper section of my website, which displays the recent post. The code for it is as follows:

    <?php if (have_posts()) : ?>
    
    <?php $recent = new WP_Query("cat=-3&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
    <?php //get article_image (custom field) ?>
    <?php $image = get_post_meta($post->ID, 'mainimage', true); ?>
    <img src="<?php echo $image; ?>" alt="<?php the_title(); ?>">
    <?php endwhile; ?>
    <?php endif; ?>

    Im happy with its results.

    But here’s the issue. When i use my search function and WHEN THERE ARE NO posts that meet that criteria, the code above does not do what its supposed to do. It just displays everything blank.

    However when the search does find a result , everything is ok.

    Its as if because the search doesnt find anything, it overwrites the code above and shows it blank.

    Any clues on what could be the problem, or could i use another search code, or something like multilple loops that doesnt alter the code above?

  • The topic ‘Search Results’ is closed to new replies.