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
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 