Get first result of S&F (Using a shortcode)

Forums › Forums › Search & Filter Pro › Get first result of S&F (Using a shortcode)

Viewing 2 posts – 1 through 2 (of 2 total)
  • Anonymous
    #247341

    Hello,

    We have set up a page with S&F with the display results method ‘Using a shortcode’.

    Before the shortcode is executed, I would like to get the first result of the query (I want to display the first item as a highlight before the complete results).

    I thought I could get the results via:

    
    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(100773)->current_query();
    

    But it seems there are no results in this object.

    Is there a way to retrieve the first item of a query from the shortcode method?

    Thanks in advance!
    -Kevin

    Trevor
    #247405

    That array fetches the search parameters array, not the results array.

    Using the Shortcode display method, you will be using the results.php template, and this follows standard WordPress Codex coding.

    All you would need to do is set set a counter variable before the while loop starts, e.g.

    $post_counter = 0;

    Then, in the first line inside the while loop, increment that by 1:

    c++;

    I think that would do it. Then use an If to test if it equals 1 and do special HTML, otherwise do normal.

    if ( $post_counter == 1 ) :

Viewing 2 posts – 1 through 2 (of 2 total)
Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.