# Limit the Number of Reports

**URL:** <https://community.hivepress.io/t/limit-the-number-of-reports/9091>\
**Category:** HivePress\
**Tags:** code\
**Created:** [January 6, 2024, 3:14am UTC](https://community.hivepress.io/t/limit-the-number-of-reports/9091 "2024-01-06T03:14:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![taxidermysocial](https://community.hivepress.io/user_avatar/community.hivepress.io/taxidermysocial/32/8715_2.png) [@taxidermysocial](https://community.hivepress.io/u/taxidermysocial)\
**Post date:** [January 6, 2024, 3:14am UTC](https://community.hivepress.io/t/limit-the-number-of-reports/9091/1 "2024-01-06T03:14:26Z")

</div>

I would like to limit the amount of reports overall (not for each listing) to 5 per week. I wrote this code, but it doesn’t work. How can I fix this?

```auto
add_filter(
    'hivepress/v1/forms/listing_report/errors',
    function( $errors, $form ) {
        $user_id = get_current_user_id();

        if ( $user_id ) {
            $report_count = \HivePress\Models\Report::query()->filter(
                [
                    'user' => $user_id,
                    'date_query' => [
                        [
                            'after' => '1 week ago',
                            'inclusive' => true,
                        ],
                    ],
                ]
            )->get_count();

            if ( $report_count >= 5 ) {
                $errors[] = 'Only 5 reports per week are allowed.';
            }
        }

        return $errors;
    },
    1000,
    2
);

```

---

<div class="post-metadata">

**Author:** ![andrii](https://community.hivepress.io/user_avatar/community.hivepress.io/andrii/32/2951_2.png) [@andrii](https://community.hivepress.io/u/andrii)\
**Post date:** [January 8, 2024, 10:35am UTC](https://community.hivepress.io/t/limit-the-number-of-reports/9091/4 "2024-01-08T10:35:27Z")

</div>

Hi,

Unfortunately, we can’t provide general recommendations here, as this requires a detailed check and custom implementation. Please note that reports are just emails to the administration (so there is no Report model in the code), so you need to count each email sent, store this number somewhere, and check it. As a workaround, you can just add these kinds of emails to spam if you need to.

---

<div class="post-metadata">

**Author:** ![system](https://community.hivepress.io/user_avatar/community.hivepress.io/system/32/13990_2.png) [@system](https://community.hivepress.io/u/system)\
**Post date:** [February 7, 2024, 10:36am UTC](https://community.hivepress.io/t/limit-the-number-of-reports/9091/5 "2024-02-07T10:36:10Z")

</div>

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