$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>display a message if get form is empty|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

display a message if get form is empty

matteradmin8PV0评论

I have a CPT, where i made a filter by taxonomies. Its a simple form, where users can filter by 2 taxonomies. If the filter returns no posts because its empty i want to show a message (ex. "Sorry no Events found")

And if its possible, i want to show (after form is submitted) the filter options, which were chosen by the user. I know how i could show this with method=post, but i dont have any idea for method=get.

Thanks for help, thats what i coded so far.

    <div class="leweb_events_search">
     <form method="get" action=""> 
        <div class="leweb_select">
        <?php
            if( $terms = get_terms( array( 'taxonomy' => 'events_category', 'orderby' => 'name' ) ) ) : 

                echo '<select name="events_category"><option value="">Select category...</option>';
                foreach ( $terms as $term ) :
                    echo '<option value="' . $term->name . '">' . $term->name . '</option>';
                endforeach;
                echo '</select>';
            endif;
        ?>
        </div>

        <div class="leweb_select">
        <?php
            if( $terms = get_terms( array( 'taxonomy' => 'events_car', 'orderby' => 'name' ) ) ) : 

                echo '<select name="events_car"><option value="">Select category...</option>';
                foreach ( $terms as $term ) :
                    echo '<option value="' . $term->name . '">' . $term->name . '</option>';
                endforeach;
                echo '</select>';
            endif;
        ?>  
        </div>

 <input type="button" value="submit">       

     </form>

    </div>

I have a CPT, where i made a filter by taxonomies. Its a simple form, where users can filter by 2 taxonomies. If the filter returns no posts because its empty i want to show a message (ex. "Sorry no Events found")

And if its possible, i want to show (after form is submitted) the filter options, which were chosen by the user. I know how i could show this with method=post, but i dont have any idea for method=get.

Thanks for help, thats what i coded so far.

    <div class="leweb_events_search">
     <form method="get" action=""> 
        <div class="leweb_select">
        <?php
            if( $terms = get_terms( array( 'taxonomy' => 'events_category', 'orderby' => 'name' ) ) ) : 

                echo '<select name="events_category"><option value="">Select category...</option>';
                foreach ( $terms as $term ) :
                    echo '<option value="' . $term->name . '">' . $term->name . '</option>';
                endforeach;
                echo '</select>';
            endif;
        ?>
        </div>

        <div class="leweb_select">
        <?php
            if( $terms = get_terms( array( 'taxonomy' => 'events_car', 'orderby' => 'name' ) ) ) : 

                echo '<select name="events_car"><option value="">Select category...</option>';
                foreach ( $terms as $term ) :
                    echo '<option value="' . $term->name . '">' . $term->name . '</option>';
                endforeach;
                echo '</select>';
            endif;
        ?>  
        </div>

 <input type="button" value="submit">       

     </form>

    </div>
Share Improve this question asked Mar 13, 2019 at 8:32 LovinQuaQuaLovinQuaQua 833 silver badges19 bronze badges 3
  • And what code do you use to get events? – Krzysiek Dróżdż Commented Mar 13, 2019 at 8:41
  • "I know how i could show this with method=post, but i dont have any idea for method=get" I don't see the difference in this context. What are you having trouble with? You just need to use $_GET instead of $_POST . – Jacob Peattie Commented Mar 13, 2019 at 8:45
  • This is so embarrassing, sorry for that post... – LovinQuaQua Commented Mar 13, 2019 at 9:12
Add a comment  | 

1 Answer 1

Reset to default 0

If anyone faces the same problem, its easy to display a message with have_posts()

<?php if ( have_posts() ) {
    echo "Events gefunden";
} else {
    echo "Keine Events gefunden";
}
?>

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far