새 WordPress 웹 사이트를 만들고 있습니다. 사용자 지정 검색 페이지를 만들려고했지만 아무 것도 검색하지 않을 때 결과가 표시되지 않습니다. 그러나 쿼리에는 여전히 게시물이 있습니다.WordPress 사용자 정의 검색 페이지가 작동하지 않습니다.
$s=get_search_query();
$args = array(
's' =>$s
);
// The Query
$the_query = new WP_Query($args); // Just tested the search query
get_header();
?>
<div class="main_content">
<div class="row">
<div class="col-sm-12">
<div class="custom-breadcrumb">
<h1>News Digest ― <?php printf(__('%s', 'decouvr'), get_search_query()); ?></h1>
<?php
schema_breadcrumb();
?>
</div>
</div>
</div>
</div>
<div class="container container-most">
<div class="row">
<?php
if ($the_query->have_posts()) :
// Start the loop.
while ($the_query->have_posts()) : the_post();
get_template_part('content', get_post_format());
// End the loop.
endwhile;
// Previous/next page navigation.
docuvr_paging_nav();
// If no content, include the "No posts found" template.
else :
get_template_part('content', 'none');
endif;
?>
</div>
</div>
<?php
get_footer();
?>
사용자가 검색하려고 할 때 검색 페이지를 리디렉션해야합니다. 검색 페이지를 리디렉션하는 기능을 사용했습니다.
function search_url_rewrite() {
if (is_search() && !empty($_GET['s'])) {
wp_redirect(home_url('/news/') . urlencode(get_query_var('s')));
exit();
}
}
add_action('template_redirect', ' search_url_rewrite ');
여전히 작동하지 않습니다. 나는 이것을하기 위해 여러 가지 방법을 시도했다. 나는 여기에 쌓여있다. 기본 검색 페이지를 사용할 때 한 가지가 있습니다. 대부분 리디렉션이 필요합니다. 내가하고있는 일이 잘못되었거나 이것을 할 다른 방법이 있습니까? while ($the_query->have_posts()) : $the_query->the_post();
에
감사 남자 올바른지 확인
the_post();
에
$the_query->
을 놓친하지만 당신은 라인'$ the_query = 새로운 WP_Query ($ 인수)을 놓친; // 그냥 검색어를 테스트'. 나는 그것을 테스트했지만'$ the_query->'를 추가하지 않고 테스트했다. –'get_template_part'가 맞습니까? 그렇지 않다면'the_title(); '으로 바꾸십시오. 귀하의 코드가 나를 위해 일하고'the_post();'에'$ the_query->'를 추가하고'get_template_part'를 내 것으로 바꿨습니다. – mattkrupnik
실제로 작동하지 않습니다. –