How to restrict listing search results to "featured" or "verified" only?

Hello,

I’m trying to restrict the listing search results on the “services” page to only show listings that are either “featured” or “verified”.

Here is what I have already tried:

  • Added a custom attribute called “verified” to listings via HivePress Attributes.
  • Verified that the attribute is working properly (I can filter by it manually on the search page).
  • Tried using add_filter('hivepress/v1/models/listing/query', ...) but it seems not to affect the listings loaded on the services page.
  • Tried using add_filter('hivepress/v1/rest/listing/search', ...) but it also does not seem to trigger (no alert or change detected).
  • I confirmed that the services page loads listings via REST API (Ajax after initial page load).

Questions:

  1. What is the correct method to forcibly filter listings to only “featured” or “verified” when loading search results on the services page?
  2. Are there multiple approaches to solve this? (e.g., hook/filter, custom REST handler, template override, etc.)
  3. What is the recommended approach by HivePress for production-level sites aiming for high security and stable operations?

I want to make sure that unverified or non-featured listings are never shown to users.

Thank you in advance for your guidance!

Hi,

If this is needed for the search results only (excluding the default Listings page and category pages) you can use hivepress/v1/models/listing/search action hook, it allows to customize the search query (WP_Query), for example you can add conditions to the meta_query that hp_verified field should equal 1, the same with hp_featured field.

If you want to cover all the listing pages, then a more global hook pre_get_posts can be used, but it would require more code customizations (to prevent affecting non-listing queries).

Hope this helps

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.