Support » Fixing WordPress » 'Search' not working after change of domain name

Viewing 15 replies - 1 through 15 (of 19 total)
  • Zoe


    A quick fix would be to manually code the <form method="get" action=""> to use the correct URL.

    However, you probably need to fix the reason it’s pulling from the wrong URL, which in this case is likely because your Home URL (in General Settings) is listed incorrectly.





    And one more – remembering that there’s an extra step involved if you’ve got WordPress within a directory:

    Hey Zoe,

    Thanks for trying to help, but it seems it’s already set to ‘/’ (mentioned in the first link you supplied above) as you’ll see from the code snippet below:

    <div id="topsearch">
    				<form  method="get" action="<?php echo get_option('HOME'); ?>/">
    					<p><span class="bg_input"><input type="text" name="s" value="<?php _e('search','templatesquare'); ?>" class="inputbox" onBlur="if (this.value == ''){this.value = '<?php _e('search','templatesquare'); ?>'; }" onFocus="if (this.value == '<?php _e('search','templatesquare'); ?>') {this.value = ''; }"/></span>
    					<input type="submit" value="" class="but" /></p>
    									</div><!-- end topsearch -->

    My General settings are also set to the correct URL.

    Any other ideas? I’ve got a feeling it might be something I need to change in the mySQL database, but I don’t know what to change.



    Did you see the third link (from the Codex) regarding installing WordPress in a directory? Check out steps 4-8 under the header Using a Pre-existing Subdirectory Install

    I just copied those files over mentioned in stage 4 and now the site returns the following error when you try to access it:

    Parse error: syntax error, unexpected T_VARIABLE in /homepages/4/d250881445/htdocs/abikenew/wp-includes/option.php on line 225

    It was literally just the search bar that wasn’t working, so I really hope I haven’t just taken 10 steps back trying to fix it!



    Did you do the rest of the steps in that list?

    I did yes, up until step 7 which says to log in, which I now can’t do as the site returns an error.



    Well you can always remove the two files you copied over from the root to undo. The fact that it didn’t work points to some other type of issue.



    In the meantime, you could go into searchform.php in your theme and hardcode the action="..." URL to get the search to work.

    Lucky I kept a copy of the files I had to replace eh? 😉

    There doesn’t seem to be a searchform.php but there is a search.php. Where would you suggest to hardcode the URL and what code would I use?

     * The template for displaying Search Results pages.
     * @package WordPress
     * @subpackage Estore
     * @since Estore 1.0
    get_header(); ?>
    $sidebar_position= get_option('templatesquare_sidebar_position') ;
    	<div id="main_content">
    	<?php if($sidebar_position=='sideleft'){ ?>
    			<div id="sidebar-left">
    				<div class="box_sidebar">
    			<?php get_sidebar(); ?>
    				</div><!-- end box_sidebar -->
    			</div><!-- end sidebar -->
    	<?php } ?>
    			<div id="content">
    <h1 class="pagetitle"><?php printf( __( 'Search Results for: %s', 'templatesquare' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
    		<?php if ( function_exists('yoast_breadcrumb') ) {
    			yoast_breadcrumb('<div id="breadcrumbs">','</div>');
    		} ?>
    <?php if ( have_posts() ) : ?>
    				/* Run the loop for the search to output the results.
    				 * If you want to overload this in a child theme then include a file
    				 * called loop-search.php and that will be used instead.
    				 get_template_part( 'loop', 'search' );
    <?php else : ?>
    				<div id="post-0" class="post no-results not-found">
    					<h2 class="entry-title"><?php _e( 'Nothing Found', 'templatesquare' ); ?></h2>
    					<div class="entry-content">
    						<p><?php _e( 'Sorry, but nothing matched your search criteria. Please try again with some different keywords.', 'templatesquare' ); ?></p>
    						<?php get_search_form(); ?>
    					</div><!-- .entry-content -->
    				</div><!-- #post-0 -->
    <?php endif; ?>
    			</div><!-- end content -->
    	<?php if($sidebar_position!=''){?>
    			<div id="sidebar-right">
    				<div class="box_sidebar">
    				<?php get_sidebar(); ?>
    				</div><!-- end box_sidebar -->
    			</div><!-- end sidebar -->
        <?php }?>
    	</div><!-- end main_content -->
    <?php get_footer(); ?>


    That may have been your problem. You weren’t supposed to replace them, just copy them and add them to the root folder. They should be in BOTH the root and the subdirectory, with the changes only to the file in the root directory.

    You can add a searchform.php file. See here:

    The default code is the first Example.

    You’d want to replace
    <form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
    <form role="search" method="get" id="searchform" action="">

    There were already Index.php and .htaccess files in the root folder, so I replaced them with copies of the ones from within the subdirectory.

    I’ll take a look at adding a searchform.php now.


    Right, I got it working. I didn’t need to add a searchform.php in the end. I just changed:

    <form method="get" action="<?php echo get_option('HOME'); ?>/">

    in my header.php to

    <form method="get" action="">

    Thanks for taking a look anyway Zoe, I do appreciate it, as normally I don’t hear anything back on here. 🙂



Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘'Search' not working after change of domain name’ is closed to new replies.