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)