Search returns only the home page of the site

2

I've created the files search.php and searchform.php for a WordPress theme I'm developing. But testing the search does not return anything, showing only the home page.

I had written a query other than the default in another theme of an old project and in that theme it works normally, but in my current project this error occurs. The codes are as follows:

searchform.php

<form action="<?php bloginfo('home'); ?>" method="get" accept-charset="utf-8" id="searchform" role="search">
    <input type="text" id="campo_busca" name="busca" placeholder="Buscar" value="<?php the_search_query(); ?>"></input>
    <input id="button_busca" type="submit"></input>
</form>

search.php

<?php
/*
Template Name: Search Page
*/
?>

<?php get_header(); ?>
<main>
    <div class="content">
      <section id="conteudo_pagina">
        <p id="tempobusca"><?php $mySearch = & new WP_Query("s=$s & showposts=20"); $num = $mySearch->post_count; echo $num.' resultados de pesquisa para '; the_search_query();?> em <?php  get_num_queries(); ?> <?php timer_stop(1); ?> segundos.</p>

        <?php if ( have_posts() ) : ?>
            <?php while ( have_posts() ) : the_post(); ?>
            <div class="box internas">
              <div class="cabecalho">
                <h2>BUSCA</h2>
              </div>
            </div>
            <ul id="linha_pesquisa">
              <li>
                <article>
                    <p class="titulobusca"><a href="<?php the_permalink() ?>" rel="bookmark" title="Link permanente para <?php the_title(); ?>"><?php the_title(); ?></a></p>
                    <p class="excertobusca"><?php the_content_rss('more_link_text', TRUE, '', 30); ?></p>
                </article>
              </li>
            </ul>
        <?php endwhile; ?>
            <div id="paginacao">
                <?php if(function_exists('wp_pagenavi')) : ?>
                    <?php wp_pagenavi() ?>
                <?php else : ?>
                    <div class="maisantigos"><?php next_posts_link(__('&laquo; Mais antigos','arclite')) ?></div>
                    <div class="maisrecentes"><?php previous_posts_link(__('Mais recentes &raquo;','arclite')) ?></div>
                <?php endif; ?>
            </div>
        <?php else:?>
            <ul id="linha_pesquisa">
              <li>
                <article>
                    <h3>404 - NOT FOUND</h3>
                    <h4>Post não encontrado</h4>
                    <p>Desculpe, mas o texto que você procura não está aqui.</p>
                </article>
              </li>
            </ul>
        <?php endif; ?>
      </section>
    <?php get_sidebar(); ?>
  <?php get_footer(); ?>

How can I solve this problem?

    
asked by anonymous 21.08.2014 / 15:23

1 answer

2

I do not know why you are using a page template when the default is that the theme has a search.php dedicated to show search results. Comparing your code with Twenty Eleven I see that searchform.php has the following problems:

  • bloginfo() is deprecated, if you turn on WP_DEBUG you will see the warning. Use

    action="<?php echo esc_url( home_url( '/' ) ); ?>"
    
  • You have defined field of search as name="busca" , but you are looking for s=$s in your search.php

I did not try to create a page template for search.php and in fact I suspect that something like this can create conflicts, ideally it would be page-search.php and configure whatever it takes to make it work. Using % s of standard% works.

Your search.php has search.php left over:

$mySearch = & new WP_Query("s=

This causes a warning to skip:

  

Deprecated: Assigning the return value of new by reference is deprecated in [...]

    
21.08.2014 / 16:10