• Resolved sandswimmer

    (@sandswimmer)


    Hello,

    I wonder if you can help me with the following: I have set up your excellent plug-in to show just one result but I would like the the search engine to open the post instead of displaying the result first (where one has to click to open the page).

    So, basically, search for (e.g) 123 – the search would then open the post called 123 and not just display the post as a search result.

    If you could help me with this I would be more than happy to send you a contribution via paypal!

    • This topic was modified 6 years, 8 months ago by sandswimmer.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Sumit Singh

    (@5um17)

    Hi,

    Please check if this code snippet works for you? Please add this in theme functions.php

    
    function wp_es_redirect_search_results() {
        if (is_main_query() && is_search()) {
            global $wp_query;
            if (!empty($wp_query->posts) && count($wp_query->posts) == 1) {
                $post_url = get_permalink($wp_query->posts[0]->ID);
                if (!empty($post_url)) {
                    wp_safe_redirect($post_url);
                    exit();
                }
            }
        }
    }
    add_action( 'template_redirect', 'wp_es_redirect_search_results' );
    

    Thanks

    Thread Starter sandswimmer

    (@sandswimmer)

    That worked perfectly! Please send me your PayPal address and I’ll buy you a big coffee!

    • This reply was modified 6 years, 8 months ago by sandswimmer.
    Plugin Author Sumit Singh

    (@5um17)

    Hi,

    Glad to know it works!
    It didn’t take my that much time and I won’t ask you to pay me for this custom work. ?? However, if you are happy with the product and support and want to buy me a coffee then here you go paypal.me/5um17

    Thank you very much! ??

    • This reply was modified 6 years, 8 months ago by Sumit Singh.
    Thread Starter sandswimmer

    (@sandswimmer)

    done! Thank you again!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Search result to open post’ is closed to new replies.