<?php
/**
* Функцилнал реализующий подмену шаблона
*/
add_filter( 'stylesheet', 'wpc_swithc_theme' );
add_filter( 'template', 'wpc_swithc_theme_themp' );
function wpc_swithc_theme($current_theme){
$mobi_theme = get_option('wpc_mobile_theme','');
$res=$current_theme;
if($mobi_theme=='')
return $current_theme;
$mobile = mobile_device_detect();
switch ($_COOKIE['wpc_cookie']){
case 'wpc-full':
$res=$current_theme;
break;
case 'wpc-mobi':
if(!is_admin()){
$res=$mobi_theme;
}
break;
case NULL:
if(!is_admin()&&$mobile){
$res=$mobi_theme;
}
break;
}
return $res;
}
function wpc_swithc_theme_themp($current_theme){
$mobi_theme = get_option('wpc_mobile_theme','');
$res=$current_theme;
if($mobi_theme=='')
return $current_theme;
$mobile = mobile_device_detect();
switch ($_COOKIE['wpc_cookie']){
case 'wpc-full':
$res=$current_theme;
break;
case 'wpc-mobi':
if(!is_admin()){
$theme=wp_get_theme($mobi_theme);
$res=$theme->template;
}
break;
case NULL:
if(!is_admin()&&$mobile){
$theme=wp_get_theme($mobi_theme);
$res=$theme->template;
}
break;
}
return $res;
}
?>
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(); ?>
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');