Display attribute options with listing counts

Good day community.

Beginner here.

We have catagories and important attributes that we created. Im trying to display the attributes on the home page with the total listings in each attribute (googling i see that it must be a select or radio or checkbox option to qualitfy for the taxonomy of hivepress)

I tried everything but cant seem to get this right.

I can easily just use a grid with pictures and a link to each attribute page. But listing the count… cant find a solution

Any help would be appreciated

Thanks for your message — our team will reply shortly.

In the meantime, you can also get instant help from our AI Assistant, familiar with all the docs and solutions we’ve shared over the years.

Hi,

This block isn’t available at the moment. It’s something we’re planning to add in the future.

In the meantime, you can try using plugins like Content Views – Post Grid & List Layouts, which can help you display and query content in a similar way.

Hope this helps

I tried using that plugin but I dont know how to select Hivepress taxonomy… the plugin only has the default taxonomy of wordpress… for post.. blogs etc

Is there a php code i can use just to get the count… will design the blocks myself and links.

I can see in the backend the tags are counted… how can i just call that count for front end display.

Not sure how to do it with the attibutes

Hey @jptromp,

I asked the HivePress AI to provide some code, and here’s what it came up with:

Retrieving a Count of Listings with a Specific Attribute

Based on the training data, here’s how you can retrieve a count of listings that have a specific attribute:

Using the HivePress Query API
You can use the HivePress\Models\Listing::query() method with filters to count listings with a specific attribute:

$listing_count = \HivePress\Models\Listing::query()
    ->filter([
        'attribute_name' => 'attribute_value',
        'status' => 'publish',
    ])
    ->get_count();

Example
If you want to count listings with a specific custom attribute, replace attribute_name with your actual attribute field name and attribute_value with the value you’re looking for.

Important Notes

  • Custom Attributes: If the amount/value is stored as a custom attribute you added in Listings/Attributes, you can access it directly from the listing object using: $listing->display_attributenamehere() (where attributenamehere is your field name)
  • View Full Values; You can use var_dump($listing->serialize()); to see the complete array of listing values along with all field names

Additional Filtering Options
You can combine multiple filters in the same query:

$listing_count = \HivePress\Models\Listing::query()
    ->filter([
        'vendor' => $vendor_id,
        'status' => 'publish',
        'sold' => false,
    ])
    ->get_count();

I hope this helps!

Cheers,
Chris :victory_hand:

Thanks chris. Ok lets say i insert this code in the code snippit plugin

$listing_count = \HivePress\Models\Listing::query()
->filter([
tender_type’ => ‘counsil_tender’,
tender_type’ => ‘goverment_tender
tender_type’ => ‘padstal_tender
‘status’ => ‘publish’,
])
->get_count();

On the front end… how would i display this count for a specific attribute then?

I want it displayed as the catagories are displayed

i created a grid with images that links to the specific attribute page… just need the count

Whilst googleing :blush: it says the attribute should have a select/radio or checkbox function to work… which this has

Hi @jptromp,

This isn’t something I’ve personally tried, (and, I’m not a qualified developer or HivePress staff), but nevertheless; here’s the HivePress AI answer:

Displaying the Listing Count on the Front End

To display the count you’ve retrieved, you need to create a shortcode that you can use anywhere on your site (pages, templates, etc.).

Complete Code Snippet
Here’s how to modify your code to create a shortcode:

add_shortcode( 'listing_count', function() {
    $listing_count = \HivePress\Models\Listing::query()
        ->filter([
            'tender_type' => 'counsil_tender',
            'status' => 'publish',
        ])
        ->get_count();
    
    return '<div class="listing-count">' . esc_html( $listing_count ) . '</div>';
} );

How to Use It

  • Add the code snippet above to your Code Snippets plugin
  • On any page/post where you want to display the count, use:
[listing_count]

Important Notes
:warning: Your filter syntax has an issue — you’re using ‘tender_type’ three times, which means only the last value will be used.

If you want to count listings with ANY of those tender types, use this instead:

add_shortcode( 'listing_count', function() {
    $listing_count = \HivePress\Models\Listing::query()
        ->filter([
            'tender_type__in' => ['counsil_tender', 'goverment_tender', 'padstal_tender'],
            'status' => 'publish',
        ])
        ->get_count();
    
    return '<div class="listing-count">' . esc_html( $listing_count ) . '</div>';
} );

Customizing the Display
You can style the output by adding CSS classes or HTML:

return '<div class="listing-count"><strong>Total Tenders:</strong> ' . esc_html( $listing_count ) . '</div>';

I hope this helps!

Cheers,
Chris :victory_hand:

Chris… if you lived near South Africa… i would bring you a “braaibroodjie”. (If someone in SA give you that.. .they like you. its food with the value in gold. Thank you sir… )

Last question. I dont know alot about coding but the flow makes sense…

If I use the short code, it will return all the attribute values count.

Should i create 4 different snippits… lets say “listing_count1”, “listing_count2” etc… so i can call the specific attributes values count?… as i need to attached the count to individual image to display in the right block

1 Like

Hey @jptromp,

Haha, you’re very welcome, and I’m pleased to hear you’re making some progress with this now! :partying_face:

Yes, I believe what you describe to be correct, in that you may one snippet per Attribute count.

You should be able to simply use ‘count1’, ‘count2’, and so on, for each shortcode.

I hope this helps!

Cheers,
Chris :victory_hand:

Yes, third-party plugins may not support displaying the post (listing is a custom post type) counts for taxonomy terms – this depends on the plugin. If you’re familiar with coding, I recommend creating a custom shortcode that outputs the grid, for example:

[my_taxonomy_grid taxonomy="taxonomy_name_here"]

In the shortcode implementation, you can query taxonomy terms via get_terms() – Function | Developer.WordPress.org (for attribute options, taxonomy name is “hp_listing_fieldnamehere”, for tags it’s “hp_listing_tags”). Once you get an array of terms, you can output an HTML grid via a loop like:

foreach ($terms as $term) {
// output HTML here, you can get the count via $term->count
}

If you have terms, there’s no need to calculate the count for each term as it’s already cached and stored in $term->count. The term name (for example, the tag name) is stored in $term->name. This way, it’s possible to compose and output an HTML grid of terms (tags or attribute options) along with listing counts.

Hope this helps

1 Like