Skip to main content

limited feeds in spaces to once daily. Anyone?

Anyone know how?

There's no built-in setting for this yet, but you can do it with a small code snippet. Add it with a plugin like FluentSnippets or Code Snippets, or put it in your child theme's functions.php:

add_filter('fluent_community/feed/new_feed_data', function ($data, $requestData) {
    // Only applies to space posts; space admins/moderators are not limited
    if (empty($data['space_id']) || !empty($requestData['is_admin'])) {
        return $data;
    }

    // Limit only specific spaces, e.g. [3, 7]. Leave empty to limit all spaces.
    $limitedSpaceIds = [];
    if ($limitedSpaceIds && !in_array((int) $data['space_id'], $limitedSpaceIds, true)) {
        return $data;
    }

    $alreadyPosted = \FluentCommunity\App\Models\Feed::where('user_id', $data['user_id'])
        ->where('space_id', $data['space_id'])
        ->where('created_at', '>=', current_time('Y-m-d') . ' 00:00:00')
        ->exists();

    if ($alreadyPosted) {
        throw new \Exception('You can only post once per day in this space.');
    }

    return $data;
}, 5, 2);

What it does:

  • Each member can createΒ one post per space per day. A second attempt shows the error message instead of publishing.
  • The limit resets at midnight in your site's timezone (Settings β†’ General).
  • Space admins, space moderators and community moderators aren't affected.
  • To limit only certain spaces, put their IDs inΒ $limitedSpaceIds.

Test it with a regular member account before rolling it out. I checked it and it works.

arjun arjun

Tawsif Ahmed RiyadΒ very helpful.