WordPress.org

Ready to get started?Download WordPress

Forums

Search function: If only one matching result, go right to that page directly. (12 posts)

  1. benfranklin
    Member
    Posted 2 years ago #

    The subject says it all, say you run a search for "tree" and there is only one matching result instead of showing you the title of the result and an excerpt, how about just direct you right to the full content for that entry?

    Anyone executed this functionality, know of a solution or have thoughts on one? I wanted to poll the community first before attempting to write one.

    If I have to write one I am thinking of using the search counter, and doing something like ... in search.php in the header put a redirect condition before any other PHP that says, If search results = 1 .... Redirect to the_permalink

    Just a thought .. not sure it would work.

  2. benfranklin
    Member
    Posted 2 years ago #

    Can anyone help with this?

  3. rajdeepsingh
    Member
    Posted 2 years ago #

    can anyone reply to my post anyone der
    http://www.tempsens.com

  4. xionkid
    Member
    Posted 1 year ago #

    Please, I need an awnser to this problem to. Can anyone help?

  5. esmi
    Forum Moderator
    Posted 1 year ago #

    I don't think this is possible. Nor is it really desirable. Standard behaviour when running any search is to display a listing of results - even if there is only 1 or even none. To change this basic behaviour could create severe problems for some site visitors. Best I can suggest is that you try looking for a plugin that replicates Google's "I'm Feeling Lucky" functionality. That, at least, should be understood by visitors.

  6. xionkid
    Member
    Posted 1 year ago #

    Okey, but if I realy want to have this function. How would I proceed?

  7. esmi
    Forum Moderator
    Posted 1 year ago #

    Try looking for a suitable plugin.

  8. xionkid
    Member
    Posted 1 year ago #

    Yeah, but there are none. So benfranklins question remains.. It can't be that hard?

  9. esmi
    Forum Moderator
    Posted 1 year ago #

    I'm sorry but I cannot magic up a suitable plugin for you. I can only suggest that you try using Google to find an existing plugin or consider building a plugin yourself.

  10. xionkid
    Member
    Posted 1 year ago #

    This is a BIG foum with more users than you (no disrespect). Maybe someone alse can help?

  11. benfranklin
    Member
    Posted 1 year ago #

    Wow! Realize I posted this 10 months ago but I did figure out a hack ... basically you could just count how many posts in your loop and right a conditional so if there is only one result, just redirect to the_permalink for that one post ...

    Looks something like this:

    <?php
          $i = 0;
    				while (have_posts()) : the_post();
    				$i++;
    			?>
    
    			<?php if (($count == 1)) { ?>
    
    <script type="text/javascript"><!--
    window.location = "<? the_permalink(); ?>"
    //--></script>			
    
    		<? 	} else { ?>
    
    <? } ?>

    I don't use it anymore because I felt like it wasn't that big of a deal to have users just click on the result even if only one but while I had it running on my site it worked even if it probably is a little ghetto ... only solution I came up with.

  12. xionkid
    Member
    Posted 1 year ago #

    Thx Ben!

    Is this the the correct code and where do I insert it? I guess in the search.php somewhere?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.