javascript - Custom AJAX search by tags WP -


i have been created custom search form in wordpress theme. looks like:

<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 tag" value="<?php echo get_search_query() ?>" name="s" title="search" /> 

and realized custom ajax search post title. task search tags. don't know how can that. search post title located in functions.php , looks like:

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(); } 

how can realize search tags only?

from codex :

show posts several tags

display posts have "either" of these tags:

$query = new wp_query( array( 'tag' => 'bread,baking' ) ); 

display posts have "all" of these tags:

$query = new wp_query( array( 'tag' => 'bread+baking+recipe' ) ); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -