For anyone hoping to limit the amount of listings per day, use this code:
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(),
'date_query' => [
[
'after' => '1 day ago',
'inclusive' => true,
],
],
]
)->get_count();
if ( $listing_count >= 10 ) {
$errors[ ] = 'Only 10 Listings per day are allowed.';
}
}
return $errors;
},
1000,
2
);
Where to edit:
- change â10â to the amount of listings per day
- if you would like to limit the amount of listings per week, change âafterâ => â1 day agoâ, to âafterâ => â1 week agoâ,.
- if you would like to limit the amount of listings per month, change âafterâ => â1 day agoâ, to âafterâ => â1 month agoâ,.
- donât forget to change $errors if you are changing the limit!
2 Likes
andrii
3
Hi,
Thank you for your solution, it will be useful for our community.
rlbc
4
Hi,
This solution is not working !
@ihor mentioned that :
" Regarding the listing query, currently thereâs no âbetweenâ operator support for dates in our API, but you can always use a fallback for the WP_Query, via $query->set_args($args)
you can provide the WP_Query args for dates WP_Query â Class | Developer.WordPress.org ."
Source : Customizing vendor images and query arguments
Using âdate_queryâ seems not to be compatible with Hivepress API.
Please, let me know if I am wrongâŚ
tharlab
5
i think UR correct, i am using buildin WP Query
ihor
7
Yes, please try using the same snippet but move the date_query
to the ->set_args()
after the ->filter()
, it should be ok then.
rlbc
8
$listing_count = \HivePress\Models\Listing::query()->filter(
[
'status__in' => [ 'publish', 'pending', 'draft' ],
//Others filters here
]
)->set_args(
['date_query' => [
[
'after' => '1 day ago',
'inclusive' => true,
],
],
]
)
->get_count();
Yes, this solution will work indeed.
Many thanks @ihor
2 Likes
system
Closed
9
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.