現在,wordpressにてWORKSのタクソノミーによる絞り込み検索を実装しているのですが、
絞り込みまでは問題なく実装できている状態なのですが、
index.phpにて出力している記事に付随しているタクソノミーをクリックした際に、
遷移先をtaxonomy.phpではなくクリックしたタクソノミーで絞り込まれているsearch.phpに遷移させたいのですが
実装方法などございましたらご教授お願いいたします。
下記が、index.phpにおける該当部分になります。
タクソノミーを出力している部分は<ul class="meta-list">
の部分からになります。
<section class="section section-project"> <h2 class="section-title section-title__project">Project</h2> <div class="project-wrapper"> <ul class="project-list"> <?php global $query_string; query_posts( Array( 'post_type' => array( 'works' ), 'tax_query' => array( array( 'taxonomy' => 'pickup', //タクソノミー名を指定 'field' => 'slug', 'terms' => 'pickup', 'operator' => 'IN' //'AND'、'IN'、'NOT IN'の何れかを指定 ) ), // 'showposts' => 5, 'posts_per_page' => 6, 'paged' => get_query_var('paged') ) ); if (have_posts()) { while (have_posts()) { the_post(); ?> <li class="project-listItem f-right"> <a href="<?php the_permalink(); ?>"> <div class="project-img"> <?php the_post_thumbnail(); ?> </div> <h3> <span><?php the_title(); ?></span> </h3> </a> <div class="project-meta"> <ul class="meta-list"> <?php $terms = get_the_terms($post->ID,'service'); foreach( $terms as $term ) { echo '<li><a href="'.get_term_link($term->slug,'service').'">'.$term->name.'</a></li>'; } ?> <?php $terms = get_the_terms($post->ID,'categorytag'); foreach( $terms as $term ) { echo '<li><a href="'.get_term_link($term->slug,'categorytag').'">'.$term->name.'</a></li>'; } ?> <?php $terms = get_the_terms($post->ID,'people'); foreach( $terms as $term ) { echo '<li><a href="'.get_term_link($term->slug,'people').'">'.$term->name.'</a></li>'; } ?> </ul> </div> <a href="<?php the_permalink(); ?>" class="btn btn-project btn-more"> <span>more</span> </a> </li> <?php } }else{ } wp_reset_query(); ?> </ul> <a href="<?php echo home_url("/works"); ?>" class="btn btn-all"> <span>All Projects</span> </a> </div> </section>
search.php <section class="section section-project"> <h2 class="section-title section-title__project"> <img src="<?php echo get_template_directory_uri(); ?>/img/common/project-title@144x-8.png" alt="project"> </h2> <div class="s-btn"> <span> search </span> </div> <?php get_search_form(); ?> <div class="project-wrapper"> <ul class="project-list"> <?php $service_terms_pros = get_terms('service',array( 'orderby' => 'term_order','order' => 'ASC', 'parent'=>'0' )); //親タームを取得 foreach($service_terms_pros as $service_term_pros){ $service_terms[] = $service_term_pros; $service_terms_elems = get_terms('service',array( 'orderby' => 'term_order','order' => 'ASC', 'parent'=> $service_term_pros->term_id )); //子タームを取得 foreach ($service_terms_elems as $service_terms_elem){ $service_terms[] = $service_terms_elem; } } $service = array(); $services = array(); $service_selected = array(); $services = isset($_GET['service']) ? ($_GET['service']) : null; if($services){ foreach($services as $value){ //get値がある場合は該当項目をセット $service[]=htmlspecialchars($value); $service_selected[]=htmlspecialchars($value); } }else{ foreach($service_terms as $service_term){ //get値がない場合は全項目をセット $service[] = $service_term->slug; } } $category_terms_pros = get_terms('categorytag',array( 'orderby' => 'term_order','order' => 'ASC', 'parent'=>'0' )); //親タームを取得 foreach($category_terms_pros as $category_term_pros){ $category_terms[] = $category_term_pros; $category_terms_elems = get_terms('categorytag',array( 'orderby' => 'term_order','order' => 'ASC', 'parent'=> $category_term_pros->term_id )); //子タームを取得 foreach ($category_terms_elems as $category_terms_elem){ $category_terms[] = $category_terms_elem; } } $category = array(); $categories = array(); $category_selected = array(); $categories = isset($_GET['category']) ? ($_GET['category']) : null; if($categories){ foreach($categories as $value02){ //get値がある場合は該当項目をセット $category[]=htmlspecialchars($value02); $category_selected[]=htmlspecialchars($value02); } }else{ foreach($category_terms as $category_term){ //get値がない場合は全項目をセット $category[] = $category_term->slug; } } $people_terms_pros = get_terms('people',array( 'orderby' => 'term_order','order' => 'ASC', 'parent'=>'0' )); //親タームを取得 foreach($people_terms_pros as $people_term_pros){ $people_terms[] = $people_term_pros; $people_terms_elems = get_terms('people',array( 'orderby' => 'term_order','order' => 'ASC', 'parent'=> $people_term_pros->term_id )); //子タームを取得 foreach ($people_terms_elems as $people_terms_elem){ $people_terms[] = $people_terms_elem; } } $people = array(); $peoples = array(); $people_selected = array(); $peoples = isset($_GET['people']) ? ($_GET['people']) : null; if($peoples){ foreach($peoples as $value03){ //get値がある場合は該当項目をセット $people[]=htmlspecialchars($value03); $people_selected[]=htmlspecialchars($value03); } }else{ foreach($people_terms as $people_term){ //get値がない場合は全項目をセット $people[] = $people_term->slug; } } $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $the_query = new WP_Query( array( 'post_status' => 'publish', 'post_type' => 'works', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'service', 'field' => 'slug', 'terms' => $service, ), array( 'taxonomy' => 'categorytag', 'field' => 'slug', 'terms' => $category, ), array( 'taxonomy' => 'people', 'field' => 'slug', 'terms' => $people, ), ), 'paged' => $paged, 'posts_per_page' => -1, // 表示件数 'orderby' => 'date', 'order' => 'DESC', ) ); if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); $service_label = get_taxonomy( 'service' )->label; $service_arr = wp_get_object_terms($post->ID, 'service',array( 'orderby' => 'term_order' )); $category_label = get_taxonomy( 'categorytag' )->label; $category_arr = wp_get_object_terms($post->ID, 'categorytag',array( 'orderby' => 'term_order' )); $people_label = get_taxonomy( 'people' )->label; $people_arr = wp_get_object_terms($post->ID, 'people',array( 'orderby' => 'term_order' )); ?> <li class="project-listItem"> <a href="<?php the_permalink(); ?>"> <div class="project-img"> <div style="background-image:url('<?php $image = get_field('kv'); if( !empty($image) ){ echo $image['sizes'][ "medium" ]; } ?>')"></div> </div> <p class="project-meta"> <?php the_time('Y.m.d'); ?> </p> <h3 class="project-title"> <span><?php the_title(); ?></span> </h3> </a> <ul class="meta-list meta-list__project"> <?php $works_url = get_post_type_archive_link('works'); foreach(['service', 'categorytag', 'people'] as $tax){ $terms = get_the_terms($post->ID, $tax); foreach( $terms as $term ) { echo '<li><a href="'.$works_url.'?s='.urlencode($tax.','.$term->slug).'">'.$term->name.'</a></li>'; } } ?> </ul> <a href="<?php the_permalink(); ?>" class="btn btn-project btn-more"> <span>more</span> </a> </li> <?php endwhile; else :?> <li> <p> 条件に合致する記事はありません </p> </li> <?php endif;?> </ul> </div> </section>
回答2件
あなたの回答
tips
プレビュー