[resolved] How to get search form to work on static page? (9 posts)

  1. garbonzo
    Posted 9 years ago #


    I've got a static page working where it's a total mirror of my wp's front page. There's only one problem: a search does nothing; the static page 'blinks' and stays the same.

    But if I do search from my wp's front page, search is fine.

    Here's the code:
    <?php include (TEMPLATEPATH . '/searchform.php'); ?>

    Do I change TEMPLATEPATH or '/searchform.php' ?


  2. moshu
    Posted 9 years ago #

    Out of the box WP doesn't search Pages. You need a plugin to search your "static" Pages. I just cannot find now its location, but you may want to look around in the Plugins section or do a search here.

  3. garbonzo
    Posted 9 years ago #

    Thx for the reply moshu, but I should clarify what I meant.

    I don't need it to search static pages, I just it need to display the same results as if the search was done from within wp. If I do a search from the static page, nothing happens. Doing the same search from my wp's front page works fine.

    So I thought I need to change something in that line:
    <?php include (TEMPLATEPATH . '/searchform.php'); ?>

    But I don't know what to change. Do you know?


  4. moshu
    Posted 9 years ago #

    That line
    <?php include (TEMPLATEPATH . '/searchform.php'); ?> doesn't mean anything. What is in the searchform... might be the casue. But I am not a coder, so I have no idea why it doesn't work.
    What theme is that?

  5. brittanie
    Posted 9 years ago #

    Okay, where is this static page located? Is it one of WordPress's "Pages" or is it something you created completely independent of wordpress?

    When you do a search through wordpress's basic search, the way it works it it queries the wp database column where all the posts live, returning only results that appear in posts. To get a search to work on a WP Page, you should use a plugin so the search queries both the posts column and the pages column. I use Search Pages.

    However, if the mirror page is a page you created independently from wordpress, then the reason you are getting no search results is because that mirror page is not "hooked up" to the wordpress database. In other words, there is no communication between that page and the database like there is with real wordpress pages.

    I don't know how to fix this, but maybe this extra info will help you search a little deeper.

  6. moshu
    Posted 9 years ago #

    I guess the OP is referring to the issue that the search function works only when performed from the main page.
    He should be able to put that in the search here :)

  7. garbonzo
    Posted 9 years ago #

    Brittanie, you made total sense about the static page needing to be 'connected,' so I looked for that while searching through Moshu's link. And Moshu, you're right about the searchform. Found the solution in your link.

    But let me clarify the situation, and I'll explain the answer.

    My wp is installed to a folder. I created a static front page for the gateway of my site, which I then configured to 'pull' all of the content from my wp's front page. So site.com/index.php 'mirrors' site.com/wpinstall/index.php

    Problem as stated above, is that searches while on site.com didn't work, while searches from site.com/wpinstall/ worked fine.

    The solution was to go into the search form and change the "action" command to /wpinstall/index.php
    instead of <?php echo $_SERVER['PHP_SELF']; ?>

    And now all is well, and I can go to sleep.

    Thanks guys!

  8. hypoluxa
    Posted 8 years ago #

    garbonzo... Your idea works great! Since I have my install in a directory I want hidden from the public your solution didn't quite work. After
    inserting the action command into my search feild
    I got a reply from the search, but the URL showed my hidden directory.

    Here's how I figured out how to hide the directory:
    1- Copied the /wpinstall/index.php file and renamed it "search.php" and copied it to my root.

    2- Changed line four of "search.php" to reflect the path to my hidden directory:

    3- Opened up the searchform.php in my theme.

    4- Replaced the the "action" command to /wpinstall/index.php
    instead of <?php echo $_SERVER['PHP_SELF']; ?> <--THANKS TO garbonzo

    5- Saved the searchform.php to searchform-mail.php and uploaded that file to my theme.

    6- In the header.php in my theme I changed the
    <?php include (TEMPLATEPATH . '/searchform.php'); ?> to read: <?php include (TEMPLATEPATH . '/searchform-main.php'); ?></div> and it worked like a champ.

    Now my search reply comes back with:

    It's a bit cumbersome, but it worked for me

  9. moshu
    Posted 8 years ago #

    ONE post is enough. Please, don't double post!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.