2016-06-16 2 views
0

나는 내 wordpress 웹 사이트 중 하나에서 평면 테마를 사용하고 있습니다. "이슈 트래커"와 같은 여러 단어를 쓸 때이 검색에서 작동하지 않습니다. 한 단어의 경우 "문제"또는 "추적자"처럼 잘 작동합니다.wordpress 검색이 여러 단어로 작동하지 않습니다

<form method="get" id="searchform" action="<?php echo esc_url(home_url('/')); ?>"> 
     <label for="s" class="assistive-text"><?php _e('Search', 'flat'); ?></label> 
     <input type="text" class="field" name="s" id="s" placeholder="<?php esc_attr_e('Search', 'flat'); ?>" /> 
     <input type="submit" class="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e('Search', 'flat'); ?>" /> 
    </form> 

내 search.php 파일은 다음과 같습니다 : searchform.php 파일의 코드입니다

<?php get_header(); ?> 

<?php flat_hook_search_before(); ?> 
    <h1 class="page-title"><?php printf(__('Search Results for: %s', 'flat'), get_search_query()); ?></h1> 
    <div id="content" class="site-content" role="main"> 
     <?php flat_hook_search_top(); ?> 

    <?php if (have_posts()) : ?> 

     <?php while (have_posts()) : the_post(); ?> 
      <?php get_template_part('content', get_post_format()); ?> 
     <?php endwhile; ?> 
     <?php the_posts_pagination(array('prev_text' => __('<i class="fa fa-chevron-left"></i>', 'flat'), 'next_text' => __('<i class="fa fa-chevron-right"></i>', 'flat'))); ?> 
    <?php else : ?> 
     <?php get_template_part('content', 'none'); ?> 
    <?php endif; ?> 

     <?php flat_hook_search_bottom(); ?> 
    </div> 
    <?php flat_hook_search_after(); ?> 
<?php get_footer(); ?> 

가 이전에 내 지역 설정 작업을했지만, 지금은 내 라이브 버전에서 작동하지 않습니다.

해결 방법을 제안하십시오.

답변

0

이 문제를 해결하기 위해 많은 노력을했지만 해결할 수 없습니다. 내 검색을 수정하려면 사용자 지정 SQL 쿼리를 사용하여 잘 작동합니다.

나는 여러 단어에 대해 작동해야하는 게시물 제목과 콘텐츠에 대한 간단한 WordPress 검색이 필요합니다. functions.php에서

넣고이 : 다음과 같이

function custom_sql_for_search() { 

    global $wpdb; 

    $search_string = esc_sql($_GET['s']); 


    $sql = "SELECT * FROM {$wpdb->base_prefix}posts WHERE 

       (post_title LIKE '%".$search_string."%' OR post_content LIKE '%".$search_string."%') 
       AND (post_status = 'publish') 
       ORDER BY post_type DESC, post_date DESC"; 

       $query=$wpdb->get_results($sql); 

       foreach ($query as $post) { 
         $result[$post->ID] = $post->ID; 
       } 

      return $result; 
} 

지금 내 search.php 코드를 수정 다음과 같이 내 코드는

<?php get_header(); 

flat_hook_search_before(); 

$search_result = custom_sql_for_search(); 

     ?> 

      <h1 class="page-title"><?php printf(__('Search Results for: %s', 'flat'), get_search_query()); ?></h1> 

     <div id="content" class="site-content" role="main"> 

     <?php flat_hook_search_top(); 

      if (count($search_result) > 0) { 
      foreach($search_result as $post) { 

       $post = get_post($post->ID); 
       setup_postdata($post); 

       get_template_part('content', get_post_format()); 

      } 


     } else { 

      get_template_part('content', 'none'); 
     } 

     flat_hook_search_bottom(); 

    ?> 
     </div> 

<?php flat_hook_search_after(); 
     get_footer(); ?> 

내 검색 후 여러 단어를 위해 노력하고 있습니다 이. 그러나 나는 여기에 또 다른 버그에 직면하고있다. 특수 문자로 검색 할 때 작동하지 않습니다. 거꾸로 쉼표, 아포스트로피 등으로 작동하지 않습니다.

누구든지이 문제를 해결할 수 있도록 도와주세요.

관련 문제