2014-10-11 3 views
0

임 새롭고 WP가 너무 좋아서 pls는 내 무지를 배우려고 노력하고 있습니다.검색 post_like + 하나의 루프에서 택시 노미 체크 박스로 검색

그래서 두 개의 Wp_Query (검색 창에 입력하여 검색하고 분류 기준에 따라 검색하여 검색) 및 나는 그들을 혼합하는 방법을 모릅니다 ... 두 번째 및 해당 cricle 작동하지 않는 경우.

<?php 

    global $search_ingr; 

    if(isset($search_ingr)) { 
     global $loop; 
    } else { 

    $query_params = getQueryParams(); 
     if(isset($query_params['search'])) { 
      $query_params['post_title_like'] = $query_params['search']; 
      unset($query_params['search']); 
     } 
    $loop = new WP_Query(array(
     'numberposts' => 60, 
     'posts_per_page' => 60, 
     'orderby' => 'title', 
     'order' => 'ASC', 
     'post_type' => 'products', 
     'post_status' => 'publish' 
     )); 
    } 
?> 


<?php if(isset($search)): ?> 
    <div class="search-matches"><h4>Wyniki wyszukiwania:</h4><hr></div> 
<?php endif; ?> 

<?php if ($loop->have_posts()) :?> 
<?php while($loop->have_posts()) : $loop->the_post(); ?> 

    <span class="tooltip tooltip-effect-4"> 
    <span class="tooltip-item"> 
     <div class="product"> 
      <a href="<?php the_permalink(); ?>"> 
       <div class="product-thumbnail"><span class="helper"></span><?php the_post_thumbnail(); ?></div> 
       <div class="product-name"><?php the_title(); ?></div> 
      </a> 
     </div> 
    </span> 
    <a href="<?php the_permalink(); ?>"> 
    <span class="tooltip-content clearfix"> 
     <?php the_post_thumbnail(); ?> 
     <span class="tooltip-text"><?php the_title(); ?></span> 
    </span> 
    </a> 
    </span> 

<?php endwhile; ?> 
<?php endif; ?> 

꽤 긴 코드의 평안함, 루프와 함께 붙이며 검색 상자와 분류 목록이 있습니다.

// $loop = new WP_Query(array(
    // 'numberposts' => 60, 
    // 'posts_per_page' => 60, 
    // 'orderby' => 'title', 
    // 'order' => 'ASC', 
    // 'post_type' => 'products', 
    // 'post_status' => 'publish' 
    // )); 

모두 검색이 잘 작동 (하지만 난 후 주문 및 게시물의 수를 제어하지 못할) :

또한 나는이를 제거 할 때. 그 어떤 도움이 필요합니까?

답변

0

Wordpress 루프를 수정하는 적절한 방법은 다음과 같습니다. 대신 상단에 PHP의 첫 번째 블록의이 시도 :

<?php 
    $search = get_query_var('s'); 
    $loop = new WP_Query(array(
     'numberposts' => 60, 
     'posts_per_page' => 60, 
     'orderby' => 'title', 
     'order' => 'ASC', 
     'post_type' => 'products', 
     'post_status' => 'publish', 
     's' => $search 
    )); 
?> 

잠재적 인 문제는 당신이 워드 프레스 네이티브 있지 않습니다 기능 및 매개 변수를 사용하는 것입니다 - getQueryParams()는 워드 프레스 기능과하지를 WP_Query 함수는 이름이 'post_title_like'인 매개 변수를 허용하지 않습니다. 이 코드가 작동하면 검색 기능을 위해 일부 플러그인을 사용 중일 수 있습니다.이 경우 기본 WordPress 쿼리가 아니라 플러그인 동작을 재정의해야합니다.

0

고맙습니다. 정말 도움 주셔서 감사하지만 그것은 내 문제를 해결하지 못했습니다. (이 코드 덤비는 시작 이유를 먹으 렴) 나는 다른 방법 모두 검색을위한 완벽하게 코드가 작동이 조각을 시도 할 것이다 그러나 나는 10의 한도 이상의 게시물의 수를 변경해야합니다

<?php 

    global $search_ingr; 

    if(isset($search_ingr)) { 
     global $loop; 
    } else { 

    $query_params = getQueryParams(); 
    if(isset($query_params['search'])) { 
     $query_params['post_title_like'] = $query_params['search']; 
     unset($query_params['search']); 
     } 

    $loop = new WP_Query($query_params); 

    } 

?> 

그리고 getQueryParams을() 함수 :

function getQueryParams(){ 
    global $query_string; 
    $parts = explode('&', $query_string); 

    $return = array(); 
    foreach($parts as $part){ 
     $tmp = explode('=', $part); 
     $return[$tmp[0]] = trim(urldecode($tmp[1])); 
    } 

    return $return; 
}