sourcetip

Wordpress: WP_커스텀 투고 타입으로 검색 조건을 적용하는 방법을 문의합니다.

fileupload 2023. 2. 9. 22:26
반응형

Wordpress: WP_커스텀 투고 타입으로 검색 조건을 적용하는 방법을 문의합니다.

커스텀 포스트 타입이 있습니다.photo다양한 기준으로 검색 키워드를 사용하여 제목 또는 설명과 일치하는 사진을 검색해야 합니다.LIKE %$search_term%, 로 시작합니다.LIKE $search_term%etc. 저는 다음과 같은 질문이 있습니다만, 이것은 다음 항목에 따라 레코드를 필터링하지 않습니다.$search_term이 요구 사항을 이 쿼리에 포함시킬 수 있는 올바른 방향을 알려주세요.

$search_term = $_GET['term'];
$search_criteria = $_GET['type'];

$loop = new WP_Query( array(
    'post_type' => 'photo',
    'posts_per_page' => 12,
    'orderby'=> 'post_date'
));

잘 부탁드립니다.저는 워드프레스에 처음 온 사람이고 제가 바보 같은 질문을 하는 것인지도 모르겠습니다.하지만 나는 정말 그것에 얽매여 있고 해결책이 필요하다.어떤 도움이라도 감사히 받겠습니다.여러분 감사합니다.

기존 인수 배열에 "s" 키를 추가합니다.

$loop = new WP_Query( array(
    'post_type' => 'photo',
    'posts_per_page' => 12,
    'orderby' => 'post_date',
    's' => 'search_term'
));

매뉴얼은 http://codex.wordpress.org/Class_Reference/WP_Query#Search_Parameter 에서 구할 수 있습니다.

다음과 같은 검색 문자열을 여기에 전달합니다( 's'=> 'test').

 <?php

 /*pass your search string here example like this ( 's'=>'test' ) */
 $args=array('s'=>'test','order'=> 'DESC', 'posts_per_page'=>get_option('posts_per_page'));

   $query=new WP_Query($args);

  if( $query->have_posts()): 

  while( $query->have_posts()): $query->the_post();

 {
   echo $post->post_title;
   echo $post->post_content;
 }

 endwhile; 
 else:
 endif;

 ?>

언급URL : https://stackoverflow.com/questions/8358595/wordpress-wp-query-how-to-apply-search-criteria-with-custom-post-type

반응형