S
S
Sergey Nesterovsky2021-06-29 19:39:36
WordPress
Sergey Nesterovsky, 2021-06-29 19:39:36

Wordpress search form not working except home page?

I made my own template for Wordpress. I connected the search, but it only works if I enter a query on the main page, nothing happens on the rest of the pages and woocommerce products.

Here is the

searchform.php file code

<form name="search" action="<?php echo home_url( '/' ) ?>" method="get" class="search-form">
  <input class="search-form__input" type="text" value="<?php echo get_search_query() ?>" name="s" placeholder="<?php echo __('Поиск по сайту ...', 'whitesquare'); ?>" >
  <button type="submit" class="search-form__btn"><?php echo __('', 'whitesquare'); ?></button>
</form>


here is functions.php if needed

<?
function enqueue_styles() {
  wp_enqueue_style( 'whitesquare-style', get_stylesheet_uri());
  wp_register_style('font-style', 'http://fonts.googleapis.com/css?family=Oswald:400,300');
  wp_enqueue_style( 'font-style');
}
add_action('wp_enqueue_scripts', 'enqueue_styles');

function enqueue_scripts () {
  wp_register_script('html5-shim', 'http://html5shim.googlecode.com/svn/trunk/html5.js');
  wp_enqueue_script('html5-shim');
}
add_action('wp_enqueue_scripts', 'enqueue_scripts');

if (function_exists('add_theme_support')) {
  add_theme_support('menus');
}
add_filter('woocommerce_add_to_cart_fragments', 'header_add_to_cart_fragment');

function header_add_to_cart_fragment( $fragments ) {
    global $woocommerce;
    ob_start();
    ?>
    <span class="basket-btn__counter">(<?php echo sprintf($woocommerce->cart->cart_contents_count); ?>)</span>
    <?php
    $fragments['.basket-btn__counter'] = ob_get_clean();
    return $fragments;
}

?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Nesterovsky, 2022-03-23
@nestercom

I found what was the problem! Looked at the source code.
It was

<form class="search-form">
<form role="search" action="https://kalibr-tools.ru/" method="get" id="searchform" class="search-form">
  <label><input type="text" value="" name="s" id="s" placeholder="Поиск по сайту .." class="search-form__input" >
  </label>
  <button type="submit" class="search-form__btn"></button>
</form>
      <button class="search-form__btn" type="submit"></button>
      <button class="search-form__open-btn" type="button"></button>
    </form>

I corrected for
<form role="search" action="https://kalibr-tools.ru/" method="get" id="searchform" class="search-form">
  <label><input type="text" value="" name="s" id="s" placeholder="Поиск по сайту .." class="search-form__input" >
  </label>
  <button type="submit" class="search-form__btn"></button>
</form>

Everything worked. Now the search works on all pages!

L
Legal Adviser, 2021-06-29
@Legal2019

Look at the implementation in any search VI theme. He usually has several files (when something is found, it is not found).
In the right place, insert: But in fact everything is well described here .
<?php get_search_form(); ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question