0

現在、専用のイベント検索ページ テンプレートでカスタム検索フィルターを作成しようとしています。

このために、日付ピッカーのカスタム フィールドを作成しました (ACF プラグインなし)。

フィールドの値を取得する方法は知っていますが、日付の間隔でイベントの記事を表示できる検索フォームでそれらを使用する方法がわかりません (例: からのイベントの記事のみを表示します)。 : 2021 年 1 月 15 日から 2021 年 2 月 21 日、リスト形式)。

検索フォーム (添付ファイルを参照) を使用して、search-events.php ページ テンプレート (以下のコードを参照) を作成しました。

<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>' ); ?>
            </header>


            <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"/>
                </form>
            </div>
            
            
            <?php
                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',
                          array(
                            'key' => 'start_of_date-de-debut',
                            'value' => $start_meta_date,
                            'type' => 'date',
                            'compare' => '>=',
                          ),
                           array(
                            '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'); ?>
                    </figure>
                <div class="post_content">
                                
                            <a href="<?php echo get_permalink($post->ID);?>" >
                                <h1>
                                    <a href="<?php the_permalink() ?>"><?php echo wp_trim_words( get_the_title(), 10 ); ?></a>
                                </h1>
                            </a>

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

ここに画像の説明を入力

4

0 に答える 0