Members can only add listings in only choosen category

Hello dear Hivepress Community,
first of all, thank you for this forum and helping each other.

Question: Can I generally forbid all users to make entries in all areas, except for the area I allow?

Example: Users cannot create hotel listings, but users can add their products to the Category “Hardware Marketplace” section. But can they continue to rate the hotel entries (award stars)?

(I dont have the Marketplace plugin - i am using ListingHive and hivepress)

Thank you in advance

Hi,

Unfortunately, there’s no such feature, it would require a custom implementation. If customizations are required for your site, please try customizing it using the collection of code snippets Search · user:hivepress · GitHub and other developer resources, or consider hiring someone for custom work Customize your website | HivePress

1 Like

Thank you andrii, sorry for my late answer but finally i fixed it and found an possible way. :heart:

First of all, i deleted with an css snippet the “category” field at “add listing” page with following code:

.hp-form__field--select:has(select[name="categories"]) {
    display: none !important;
}

than i addet an custom functions.php snippet to force/allow only add normal members in the choosen category (in my case “hardware marktplatz”) with the following code:

<?php

add_action( 'hivepress/v1/models/listing/create', 'auto_assign_hardware_marketplace_category_frontend', 10, 1 );

function auto_assign_hardware_marketplace_category_frontend( $listing ) {
    if ( ! is_admin() && ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { // Nur für Frontend-Erstellungen durch Nicht-Admins
        $hardware_category_id = 38; // Ersetze dies mit der tatsächlichen ID deiner "Hardware Marktplatz" Kategorie

        wp_set_post_terms( $listing->get_id(), $hardware_category_id, 'hp_listing_category' );
    }
}

Result: Members can only add listings in only choosen category (by my self for all users), so they click to “add listing” and fill the “selling form” and list it.

For other categories now i can only use the backend admin page.

Thank you again, and thanks for gemini helping me with the code snippet’s :slight_smile: :heart:

1 Like

Hi,

Thank you for sharing this solution, it will be useful for our community.

1 Like