WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] 'Search' not working after change of domain name (20 posts)

  1. joeysaviour
    Member
    Posted 1 year ago #

    Hi there,

    I had been building the http://www.a-bike.co.uk site in a subfolder on a-bike's server (http://www.a-bike.co.uk/abikenew) and when it came to 'going live', I then set the domain name's landing destination to be that subfolder.

    Everything works fine apart from the search bar.... If you try to type anything in the search bar, it will attempt to take you to the sub folder's URL.

    For example; if you were to type 'tyres' in the search bar it returns the following url: http://www.a-bike.co.uk/abikenew/?s=tyres
    when I'd like it to return http://www.a-bike.co.uk/?s=tyres

    Please please please can anyone help me with this problem?

    Many thanks.

  2. Zoe
    Member
    Posted 1 year ago #

    A quick fix would be to manually code the <form method="get" action="http://www.a-bike.co.uk/abikenew/"> 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.

  3. Zoe
    Member
    Posted 1 year ago #

  4. Zoe
    Member
    Posted 1 year ago #

    And one more - remembering that there's an extra step involved if you've got WordPress within a directory: http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

  5. joeysaviour
    Member
    Posted 1 year ago #

    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>
    				</form>
    									</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.

  6. Zoe
    Member
    Posted 1 year ago #

    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

  7. joeysaviour
    Member
    Posted 1 year ago #

    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

  8. joeysaviour
    Member
    Posted 1 year ago #

    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!

  9. Zoe
    Member
    Posted 1 year ago #

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

  10. joeysaviour
    Member
    Posted 1 year ago #

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

  11. Zoe
    Member
    Posted 1 year ago #

    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.

  12. Zoe
    Member
    Posted 1 year ago #

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

  13. joeysaviour
    Member
    Posted 1 year ago #

    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?

    <?php
    /**
     * The template for displaying Search Results pages.
     *
     * @package WordPress
     * @subpackage Estore
     * @since Estore 1.0
     */
    
    get_header(); ?>
    
    <?php
    $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() ) : ?>
    				<?php
    				/* 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(); ?>
  14. Zoe
    Member
    Posted 1 year ago #

    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: http://codex.wordpress.org/Function_Reference/get_search_form

    The default code is the first Example.

    You'd want to replace
    <form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
    with
    <form role="search" method="get" id="searchform" action="http://www.a-bike.co.uk">

  15. joeysaviour
    Member
    Posted 1 year ago #

    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.

    Thanks.

  16. joeysaviour
    Member
    Posted 1 year ago #

    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="http://www.a-bike.co.uk">

    Thanks for taking a look anyway Zoe, I do appreciate it, as normally I don't hear anything back on here. :-)

    Cheers,

    Joe
    `

  17. Zoe
    Member
    Posted 1 year ago #

    No problem! Usually you wouldn't have that form code in header.php, it would be called in from searchform.php.

  18. joeysaviour
    Member
    Posted 1 year ago #

    Resolved.

  19. MonkeeSeeMonkeeDoDoo
    Member
    Posted 1 year ago #

    This above info from you both was extremely helpful for me as I had the exact same issue with my main WP search, as I am also using a static.html file as my homepage, as a prettier 'shop front' basically (and use WP for a basic cms tool really) anyway...I was stuck! ...Until seeing this solution post! So thanks for that!!!

    Cheers!

  20. MonkeeSeeMonkeeDoDoo
    Member
    Posted 1 year ago #

    It works on search widgets too! But I had to change both header.php AND searchform.php

    Cheers!

Topic Closed

This topic has been closed to new replies.

About this Topic