Display Number of Listings in Search Results

This topic contains 2 replies, has 3 voices, and was last updated by  Kiran 5 years, 8 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #444122

    Guilherme Hadlich
    Expired Member
    Post count: 7

    Hello all,

    I’m trying to get my search page to display something like: “Displaying ## amount of results for places near X location, according to X, Y, Z (filters)”. I’ve been able to add the code which displays the total number of gd_places, but I wanted it to count only the results that resulted from the search. The URL of the page I’m talking about is ‘http://www.rateamdemo.com/?geodir_search=1&s=+&sgd_placecategory%5B%5D=&stype=gd_place&snear=&sgeodir_conference=&sgeodir_private_public%5B%5D=&sgeodir_division%5B%5D=&sgeo_lat=&sgeo_lon=’. I’ve added the following code:

    //The function below displays the number of results showing on Listings Page

    function display_number_results () {
    $query_args = array(
    ‘post_type’ => ‘gd_place’,
    );
    //Line below establishes the text to be displayed
    echo “Displaying “.geodir_get_widget_listings($query_args, true).” results:”;

    }

    //Line below adds the action before the list of places
    add_action(‘geodir_before_listing_listview’,’display_number_results’);

    Can someone help me with this?

    Thank you very much!

    Gui

    #444136

    Kor
    Moderator
    Post count: 16516

    Hi Gui,

    Thanks for your post. I’ll forward to this to a developer for a second look. But please keep in mind that this is considered customization and it falls outside of our support scope.

    Thanks!

    #444153

    Kiran
    Moderator
    Post count: 7069

    Hello Gui,

    You can use $numposts = $wp_query->found_posts; to retrieve posts count.

    Usage:

    
    
    global $wp_query;
    $numposts = $wp_query->found_posts;

    You can get help from current pagination function https://wpgeodirectory.com/codex/codex/geodirectory_functions/geodir_pagination/

    Kiran

Viewing 3 posts - 1 through 3 (of 3 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket