Being a beginner in the development of Wordpress theme,

I'm currently trying to create a custom search filter on a dedicated event search page template.

For this, I created custom fields of date picker (Without the ACF plugin).

I know how to retrieve the values ​​of the fields, but I don't know how to use them with a search form allowing to display the articles of events by interval of dates (example: displays only the articles of events which are from: 15 / 01/2021 to 21/02/2021, in list form).

I created a search-events.php page template (See code below) with the search form (see attached files).

<section id="primary" class="content-area col-md-12">
        <main id="main" class="site-main" role="main">
            <header class="entry-header">
                <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>

            <div class="search_form">
                <form  method="post" action="<?php bloginfo('url');?>/myevents/">
                    <?php  $start_end_event = get_post_meta( get_the_ID(), 'start_of_date-de-fin', true );
                           $start_end_event .= get_post_meta( get_the_ID(), 'end_of_date-de-fin', true );

                        foreach($start_end_event as $metasearch){
                            echo buildSelect($metasearch);
                    <input type="submit"/>
                if (get_query_var('paged')) {
                    $paged = get_query_var('paged');
                } elseif (get_query_var('page')) { // 'page' is used instead of 'paged' on Static Front Page
                    $paged = get_query_var('page');
                } else {
                    $paged = 1;

                    $args = array(
                        // Arguments for your query.
                        'post_type' => 'myevents',
                        'numberposts' => -1,
                        'post_status' => null,
                        'post_parent' => null,
                        'posts_per_page' => 10,
                        'paged' => $paged,  //very important
                        'order_by' => 'date',
                        'order' => 'ASC',
                        'meta_query' => array(
                          'relation' => 'AND',
                            'key' => 'start_of_date-de-debut',
                            'value' => $start_meta_date,
                            'type' => 'date',
                            'compare' => '>=',
                            'key' => 'end_of_date-de-fin',
                            'value' => $end_meta_date,
                            'type' => 'date',
                            'compare' => '<=',
                $custom_query = new WP_Query($args);
                if ($custom_query->have_posts()) :
                     while ($custom_query->have_posts()) : $custom_query->the_post();
                <div class="post_wrap">
                    <figure class="post_thumb">
                        <?php the_post_thumbnail('large'); ?>
                <div class="post_content">
                            <a href="<?php echo get_permalink($post->ID);?>" >
                                    <a href="<?php the_permalink() ?>"><?php echo wp_trim_words( get_the_title(), 10 ); ?></a>

                            <p class="excerpt_post">
                                <?php echo excerpt(40); ?><a href="<?php echo get_permalink($post->ID);?>" ><strong>lire la suite</strong></a>
            <?php  endwhile;  ?>

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.