PHP – don’t display results if nothing searched

I’ve taken over some custom php plugins and stylesheets from old developer and I’m bit stuck with php.

I’m trying to get it to not display results if nothing was searched for, however currently I just get a entire list of everything.

Any help would be appreciated 😉

  <div class="container">
    <div class="row">

        <div class="col-md-12">

        <ul class="qualification-listing">

    <?php

        $search = wamitab_qualification_search();
        if ($search->have_posts()) :
        while ( $search->have_posts() ) {

            $search->the_post();

            $level = wp_get_post_terms( get_the_ID(), 'qualification_level');
            if (isset($level[0])) $level = $level[0]->name; // what if not?

            $code = get_post_meta( get_the_ID(), 'wamitab_code', true );
            $download = get_post_meta( get_the_ID(), 'qualification_upload', true );

            $terms = get_the_terms( get_the_ID(), 'qualification_sector' );

            $slug = '';
            if ( is_array( $terms ) ){
                $term = array_shift( $terms );
                $slug = $term->slug;
            }
            elseif ( ! empty($terms)) { 
                $term = $terms;
                $slug = $term->slug;
            }

              ?>              
            <li class="<?php if (isset($term)) the_field('colourway', $term ); ?>">
                <div class="qualification-listing-level">Level <span class="<?php echo $level; ?>"><?php echo $level; ?></span></div>
                <h4><?php echo get_the_title(); ?></h4>
                <span class="qualification-code">WAMITAB Code: <?php echo $code; ?></span>
                <div>
                    <a class="widget-button" href="<?php echo get_permalink(73) . '?centre_qualification=' . get_the_ID(); ?>"><span class="glyphicon glyphicon-map-marker"></span> View Centres offering this Qualification</a>
                    <a class="widget-button pull-right" href="<?php echo $download['url']; ?>" download><span class="glyphicon glyphicon-download-alt"></span> Purpose statement</a>
        <a class="widget-button pull-right" href="<?php echo $download['url']; ?>" download><span class="glyphicon glyphicon-download-alt"></span> Handbook</a>
                </div>

            </li>

Read more here: PHP – don’t display results if nothing searched

Leave a Reply

Your email address will not be published. Required fields are marked *