WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Search returning a 404 (5 posts)

  1. yeleek
    Member
    Posted 6 years ago #

    Hi,
    Am designing my own theme, its gone well. However trying to create a searchpage (not using sidebar) following the instructions here

    Used these so already had searchform.php and search.php. Created the page added the <?php include (TEMPLATEPATH . '/searchform.php'); ?> all appears fine. When searching for anything though am getting a 404 error.

    Can't direct to the site as its all local at the moment...
    Searchform.php

    <form method="get" id="searchform" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <div><input type="text" value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" />
    <input type="submit" id="searchsubmit" value="Search" />
    </div>
    </form>

    Search.php

    <?php get_header(); ?>
    <div id="wrapper'>
    	<div id="content">
    
    	<?php if (have_posts()) : ?>
    
    		<h2 class="pagetitle">Search Results</h2>
    
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link('&laquo; Previous Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Next Entries &raquo;') ?></div>
    		</div>
    
    		<?php while (have_posts()) : the_post(); ?>
    
    			<div class="post">
    				<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>
    				<small><?php the_time('l, F jS, Y') ?></small>
    
    				<div class="entry">
    					<?php the_excerpt() ?>
    				</div>
    
    				<p class="postmetadata">Posted in <?php the_category(', ') ?> <strong>|</strong> <?php edit_post_link('Edit','','<strong>|</strong>'); ?>  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
    			</div>
    
    		<?php endwhile; ?>
    
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link('&laquo; Previous Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Next Entries &raquo;') ?></div>
    		</div>
    
    	<?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<?php include (TEMPLATEPATH . '/searchform.php'); ?>
    
    	<?php endif; ?>
    
    	</div>
    
    </div>
    <?php get_footer(); ?>

    Any ideas anyone?

    Thanks

  2. whooami
    Member
    Posted 6 years ago #

    I cant speak to your issue, however you have one thing in the above that you shouldnt have:

    <?php echo $_SERVER['PHP_SELF']; ?>

    dont use that, its insecure. If you got that out of the codex, it should be changed. Look at the default theme for what you ought to be using in place of that.

    There are quite a few theme authors that are not up to speed on the fact that they should not be using that there.

  3. yeleek
    Member
    Posted 6 years ago #

    OK thanks :)

    Searchform.php now changed to same as default

    <form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
    <div><input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />
    <input type="submit" id="searchsubmit" value="Search" />
    </div>
    </form>
  4. yeleek
    Member
    Posted 6 years ago #

    Whooami - Don't claim to understand it, but since making that change i'm getting search results. Weird - but hey thank you :)

  5. whooami
    Member
    Posted 6 years ago #

    youre welcome :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags