0
私はWordPressのテーマでカスタム検索フォームを作成しました。彼女は次のようになります。タグでカスタムAJAXを検索WP
<form role="search" class="form" method="get" action="<?php echo home_url('/');?>">
<input type="search" id="keyword" class="inp-search" onclick="showNewTag()" oninput="searchTags()" onkeyup="fetch()" placeholder="search by tag" value="<?php echo get_search_query() ?>" name="s" title="Search" />
と私は、POSTのタイトルカスタムAJAX検索を実現しました。しかし、私の仕事はタグによる検索です。私はそれをどうやってできるのか分かりません。 functions.phpにある投稿タイトルによる私の検索は次のようになります:
add_action('wp_footer', 'ajax_fetch');
function ajax_fetch() {
?>
<script type="text/javascript">
function fetch(){
jQuery.ajax({
url: '<?php echo admin_url('admin-ajax.php'); ?>',
type: 'post',
data: { action: 'data_fetch', keyword: jQuery('#keyword').val() },
success: function(data) {
jQuery('#grid').html(data);
}
});
}
</script>
<?php
}
add_action('wp_ajax_data_fetch' , 'data_fetch');
add_action('wp_ajax_nopriv_data_fetch','data_fetch');
function data_fetch(){
$the_query = new WP_Query(array('posts_per_page' => -1, 's' =>
esc_attr($_POST['keyword']), 'post_type' => 'post'));
if($the_query->have_posts()) :
while($the_query->have_posts()): $the_query->the_post();
if(get_field('type') == "box") {
?>
<div class="grid-item grid-item--<?php echo get_field('type');?> <?php echo get_field('position');?>" data-tooltitle="Hood Baroque" data-tooltip="Design | 3D modeling | Drawings">
<a class="linkpost" href="<?php echo get_post_permalink()?>"><img src="<?php the_field('picture');?>" alt=""></a>
<a href="<?php echo get_post_permalink()?>" class="text">
<img src="<?php the_field('svg_picture');?>" alt="">
</a>
</div>
<?php
} else {
?>
<div class="grid-item grid-item--<?php echo get_field('type');?> left" data-tooltitle="Hood Baroque" data-tooltip="Design | 3D modeling | Drawings">
<a class="linkpost" href="<?php echo get_post_permalink()?>"><img src="<?php echo get_field('picture');?>" alt=""></a>
<a href="<?php echo get_post_permalink()?>" class="text">
<img src="<?php echo get_field('svg_picture');?>" alt="">
</a>
</div>
<?php
}
endwhile;
wp_reset_postdata();
endif;
die();
}
タグで検索を実現するにはどうすればいいですか? codexから
「WP_Query」ドキュメントに記載されている適切な*「タグパラメータ」*を設定します – charlietfl