• Resolved mcl

    (@mcl)


    I have muddled together a site, from the Bare Minimum Theme.

    It is a CMS rather than a blog, but because of categories and other reasons I have forgotten, I am using posts like pages.

    After a searchform.php or tag select, I go to search.php to list my results.

    If I have only one post, I want to skip out of search.php and run single.php, but I do not seem to be able to work out how to do this.

    My pseudo code in search.php would be
    if NoOfPosts == 1 then call single.php(ThisPost)
    It may be that I do not have to pass ThisPost as WordPress may already know it.

    I am very much a novice at all this, but if any one can advise, I would be most grateful.

    Richard

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mcl

    (@mcl)

    After much more muddling. I may have found a solution, it may not be ideal, but it seems to work. Rather than calling single.php, I just call the permalink of the singly found post.

    <?php
        global $wp_query;
    
        while (have_posts()) : the_post();
        if ($wp_query->found_posts == 1) {
               header("Location:" . get_permalink());
        }
    ?>

    If there is a better solution or advice that this is not the way to do it, please advise.

    Richard

    Richard

    I think that your logic is right.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Call single.php if only one post in search.php’ is closed to new replies.