Business Listings Counter

This topic contains 17 replies, has 3 voices, and was last updated by  netbrasil 7 years, 11 months ago.

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

Open Support Ticket
  • Author
    Posts
  • #184986

    netbrasil
    Expired Member
    Post count: 133

    Hi, Is there a way to show somewhere in the site on how many listings we have already. ( E.g Business listings registered : 34 ). Do you know any extension or plugin that does this?

    #185000

    Giri
    Expired Member
    Post count: 3155

    Hi there, you have to use the following code if you need listing count.

    
    
    $query_args = array(
        'post_type' => 'gd_place',
    );
    echo geodir_get_widget_listings($query_args, true);
    #185405

    netbrasil
    Expired Member
    Post count: 133

    Thanks Tom!

    #185433

    netbrasil
    Expired Member
    Post count: 133

    Hi,

    I have added this code in my functions.php

    
    
    // Add number of listings 
    
    function listing_count(){
     
    $query_args = array(
    'post_type' => 'gd_services',
    );
    echo geodir_get_widget_listings($query_args, true);
     
    }
     
    add_shortcode('listingcount', 'listing_count');

    I’m no programmer but i hope i’m in the right track.

    Anyway, the output is 0 even though i already have a bunch of listings in gd_services post type.

    I want the total of all post types. How do we do that?

    Cheers!

    #185749

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    I asked to Giri to follow up. He’s off for the week end now, so he’ll reply on monday.

    Thanks for your patience,

    #186991

    Giri
    Expired Member
    Post count: 3155

    Hi there, You have almost made it work except that you are supposed to use return in shortcodes instead of echoing it.

    Just place this code and let me know how that goes.

    
    
    // Add number of listings 
    
    function listing_count(){
    
        $query_args = array(
            'post_type' => 'gd_services',
        );
        return geodir_get_widget_listings($query_args, true);
    
    }
    
    add_shortcode('listingcount', 'listing_count');
    #186992

    Giri
    Expired Member
    Post count: 3155

    If that doesn’t work make sure you are using the correct post type name.

    It might be

    gd_service

    instead of

    gd_services
    #187684

    netbrasil
    Expired Member
    Post count: 133

    Hi Tom,

    Added your code and tried

    gd_service

    i’m still getting 0 as a result.
    Also, i want the total of business listings of all posts types not just services

    Here’s a list of my post types

    http://prntscr.com/b29qlg

    Thank you!

    #187698

    Giri
    Expired Member
    Post count: 3155

    If you need ALL listing count, try this code

    
    
    
    // Add number of listings
    
    function listing_count(){
    
        $post_types = geodir_get_posttypes('Array');
    
        $count = 0;
    
        if (!empty($post_types)) {
            foreach ($post_types as $post_type => $cpt_info) {
                $query_args = array(
                    'post_type' => $post_type,
                );
                $output = geodir_get_widget_listings($query_args, true);
                $count = $count + (int) $output;
            }
        }
    
        return $count;
    
    }
    
    add_shortcode('listingcount', 'listing_count');
    #188088

    netbrasil
    Expired Member
    Post count: 133

    Hi Ethan,

    The shortcode output is still 0 🙂

    #188208

    Giri
    Expired Member
    Post count: 3155

    Well, everytime I give you some code I test it in my local before post here. So I think you are doing it wrong.

    Give me steps of what you have done, where do you use this shortcode, page url, login details etc to debug this issue.

    Thanks

    #189082

    netbrasil
    Expired Member
    Post count: 133

    Hi,

    I’m pasting the code in my functions.php which is located here /wp-content/themes/geodir_gdf-modern
    then added the shortcode in my text widget : http://prntscr.com/b2zpx5 and this is the result : http://prntscr.com/b2zq1s

    #189256

    Giri
    Expired Member
    Post count: 3155

    Shortcodes are not supported in widget by default.

    Make sure you have this code in your child theme.

    
    
    
    add_filter('widget_text', 'do_shortcode');

    If thats not working then i need your login details and ftp details

    #189793

    netbrasil
    Expired Member
    Post count: 133
    This reply has been marked as private.
    #189796

    Giri
    Expired Member
    Post count: 3155

    ok, I have fixed it. Looks like you don’t have any listings for that particular location. I have removed location filter. its showing count now.

    Thanks

Viewing 15 posts - 1 through 15 (of 18 total)

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

Open Support Ticket