• Hello!

    I am making a custom theme for my wordpress site in it the single page and home page are now displaying properly, my problem is with the search function, I have added the search form which looks like this:

    <form method="get" id="searchform" action="<?php bloginfo('url'); ?>">
    <div>
    <label for="searchform"></label><input class="searchinput" type="text" value="<?php if(trim(wp_specialchars($s,1))!='') echo trim(wp_specialchars($s,1));else echo ' ';?>" name="searchform" id="searchform" />
    <input type="submit" class="submitinput" name="Submit" value="Search!" />
    </div>
    </form>

    I am assuming my problem is the action in the form but I don’t know what to replace it with to be able to load the search.php instead of the home.php, I tried adding /search after the blog’s url but that gives me a page not found, I also read the documentation here
    https://codex.www.ads-software.com/Function_Reference/get_search_form

    but it says there that the action should be pointing to the home url so I am now lost, please help!!!

Viewing 15 replies - 1 through 15 (of 18 total)
  • Give us an example of what you put into the action attribute when you tried to set it to your search template.

    Thread Starter tlacaelelrl

    (@tlacaelelrl)

    fwoan: It is right there in my first post it shows the full search form, the action is bloginfo(‘url’) is that what you asked for?

    No, I’m looking for an example of what you were doing when you described this:

    I tried adding /search after the blog’s url but that gives me a page not found

    Basically, your theme should have a search results template that will execute on the submission of the form. Make sure that exists and that you are outputting the correct URL in the action attribute.

    Thread Starter tlacaelelrl

    (@tlacaelelrl)

    the search page does exist search.php and even if I have the template only display header footer and a message in the body it goes to the home page, I am using this as the form action bloginfo(‘url’)

    I also tried action=”<?php bloginfo(‘url’);?>search”
    I also tried action=”<?php bloginfo(‘url’);?>/search”

    try action="<?php bloginfo('url');?>/search.php"

    Thread Starter tlacaelelrl

    (@tlacaelelrl)

    this is the search page, I am not doing any results output until I am able to render that page when I hit the search button that is why it is empty, just echo something to know I got there

    <?php
    get_header();
    echo "in the search page";
    get_footer();
    ?>

    Oops, I mean try: action="<?php bloginfo('template_directory');?>/search.php"

    Thread Starter tlacaelelrl

    (@tlacaelelrl)

    I did what you recommended
    “try action=”<?php bloginfo(‘url’);?>/search.php””
    And this is what I got in the address bar

    https://www.medialifemagazine.com/wordpress/wordpress/search.php?searchform=+some+search&Submit=Search!

    And got 404

    Thread Starter tlacaelelrl

    (@tlacaelelrl)

    Tried the second
    bloginfo(‘template_directory’);?>/search.php”

    and got

    PHP Fatal error: Call to undefined function get_header()

    so wordpress is not processing that

    by the way, thank you for all your help!!!

    Well, you have two wordpress directories in that url. Is your site actually set up like that? Or is that incorrect?

    I think the problem goes deeper into what you have defined as your site and wordpress URLs.

    Thread Starter tlacaelelrl

    (@tlacaelelrl)

    The directory structure is like that basically is base/wordpress/wordpress/here are the inner wordpress files and folders, the rest of the site works just fine

    I think I’m out of ideas… sorry.

    Thread Starter tlacaelelrl

    (@tlacaelelrl)

    Thank you, what I did is add a hidden value in the search form and check the $_GET to see if search is set, now I am trying to figure how to access the search results, I tried with have_posts() but I got no results

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Search page redirecting to home page’ is closed to new replies.