WordPress.org

Ready to get started?Download WordPress

Forums

Custom search (8 posts)

  1. viebone
    Member
    Posted 1 year ago #

    hello,

    I made a custom theme and all is working perfect except the search form.

    I don't understand how it works and I can't make it works.

    I created a page-search.php as a page template and I added a page called search in my wordpress that uses this template.

    But I don't know what code I have to use in my page-search.php template to throw any results.

    Could anyone help me.

    Thanks a lot

  2. keesiemeijer
    moderator
    Posted 1 year ago #

  3. viebone
    Member
    Posted 1 year ago #

    Thanks,

    I followed this tutorial two times and I can't get it work.

    The problem is that I can't make my custom search page works.

    If I go to http://www.mydomain.com/wp/search it shows the sear page, but if I introducce a search string I got and error 404 page not found.

    I don't know what to do, can you help me???

    This is my custom search page:

    <?php
    
    /*
    Template Name: page-search
    Develop by Alvaro Vieitez
    Company: Framestorm
    */
    
    ?>
    
    <?php
    global $query_string;
    
    $query_args = explode("&", $query_string);
    $search_query = array();
    
    foreach($query_args as $key => $string) {
    	$query_split = explode("=", $string);
    	$search_query[$query_split[0]] = urldecode($query_split[1]);
    } // foreach
    
    $search = new WP_Query($search_query);
    ?>
    
    <?php get_header(); ?>
    
    		<div id="container">
    			Resultados de búsqueda
    
    			<?php get_search_form(); ?>
    
    		</div><!-- #container -->
    
    <?php get_footer(); ?>

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. Or better still - use the pastebin. As it stands, your code may now have been permanently damaged/corrupted by the forum's parser.]

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    Does your theme have a template file search.php.

    If not, duplicate your index.php (if it does not have a query on the loop) and rename it search.php.

    Do a search and see if it uses the search.php template for the results.

  5. viebone
    Member
    Posted 1 year ago #

    Ok, my theme didn't have a templete file search.php, but now I created it and yes, it uses it.

    Following the tutorial I think I have understood that I don't need the search.php file and that I have to created a custom searchpage.php as a template.

    What i should do now???

    Thanks a lot

  6. keesiemeijer
    moderator
    Posted 1 year ago #

    Following the tutorial I think I have understood that I don't need the search.php

    search.php is a template that displays the search results. index.php is used if your theme doesn't have a search.php.

    http://codex.wordpress.org/Template_Hierarchy#Search_Result_display

    Do you still get a 404 after a search?

  7. viebone
    Member
    Posted 1 year ago #

    No thanks, now it is working and I don't get any error.

    I was wrong, I insisted on creating a page in wordpress and assign to it a template named as page-search.php

    It is much simple just using the search.php.

    Thanks!!

  8. keesiemeijer
    moderator
    Posted 1 year ago #

    No problem. I'm glad you got it resolved :-)

Topic Closed

This topic has been closed to new replies.

About this Topic