function search_filter($query) {
if ($query->is_search) {
$query = new WP_Query(ваши параметры)
}
}
add_action('pre_get_posts','search_filter');
$args = array(
'post_type' => 'product',
'meta_query' => array(
array(
'key' => '_sku',
'value' => $_GET["s"]
),
)
);
function search_filter($query) {
if ( $query->is_main_query() ) {
if ($query->is_search) {
$query = new WP_Query($arg);
}
}
}
add_action('pre_get_posts','search_filter');
function search_filter($query) {
if ( $query->is_main_query() ) {
if ($query->is_search) {
$args = array(
'post_type' => 'product',
'meta_query' => array(
array(
'key' => '_sku',
'value' => $_GET["s"]
),
)
);
$query = new WP_Query($arg);
}
}
}
add_action('pre_get_posts','search_filter');
function search_filter($query) {
if ( $query->is_main_query() ) {
if ($query->is_search) {
global $query;
$args = array(
'post_type' => 'product',
'is_search' => true,
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => '_sku',
'value' => $_GET["s"],
'compare' => 'like',
)
)
);
$query = new WP_Query($args);
return $query;
}
}
}
add_action('pre_get_posts','search_filter');
get_header();
global $query;
?>
<section id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if ( $query->have_posts() ):;?>
<header class="page-header">
<h1 class="page-title"><?php printf( __( 'Search Results for: %s', 'twentyfifteen' ), get_search_query() ); ?></h1>
</header><!-- .page-header -->
<?php
// Start the loop.
while ( $query->have_posts() ): $query->the_post(); ?>
<?php
/*
* Run the loop for the search to output the results.
* If you want to overload this in a child theme then include a file
* called content-search.php and that will be used instead.
*/
get_template_part( 'content', 'search' );
// End the loop.
endwhile;
// Previous/next page navigation.
the_posts_pagination( array(
'prev_text' => __( 'Previous page', 'twentyfifteen' ),
'next_text' => __( 'Next page', 'twentyfifteen' ),
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyfifteen' ) . ' </span>',
) );
// If no content, include the "No posts found" template.
else :
get_template_part( 'content', 'none' );
endif;
?>
</main><!-- .site-main -->
</section><!-- .content-area -->
<?php get_footer(); ?>