Skip to content

Instantly share code, notes, and snippets.

@hivepress
Created May 4, 2022 20:18
Show Gist options
  • Save hivepress/cf7befc6e60ed4ad5ed9d148bda493a3 to your computer and use it in GitHub Desktop.
Save hivepress/cf7befc6e60ed4ad5ed9d148bda493a3 to your computer and use it in GitHub Desktop.
Limit the maximum number of listings per user account #hivepress #listings
<?php
add_filter(
'hivepress/v1/forms/listing_submit/errors',
function( $errors, $form ) {
$listing = $form->get_model();
if ( $listing && $listing->get_user__id() ) {
$listing_count = \HivePress\Models\Listing::query()->filter(
[
'status__in' => [ 'publish', 'pending', 'draft' ],
'user' => $listing->get_user__id(),
]
)->get_count();
if ( $listing_count >= 123 ) {
$errors[] = 'Only 123 listings per account are allowed.';
}
}
return $errors;
},
1000,
2
);
@theabbott1911
Copy link

@hivepress I couldn't get this to work after adding. Nothing seems to happen to when a user tires to create another listing.

@hivepress
Copy link
Author

Please make sure that you changed 123 to another limit, it should throw an error once the limit is exceeded.

@tharlab
Copy link

tharlab commented Dec 14, 2023

@hivepress hi how to limit user post created by date daily/weekly "created_date__between" or "created_date__in" ??

@hivepress
Copy link
Author

Please post a new topic here and we'll provide some guidance https://community.hivepress.io/c/development/5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment