Anyone know how to block new posts per category if a limit has been reached?

Hi all,

I'm faced with a interesting puzzle related to my little homemade ad system described here:
https://premium.wpmudev.org/forums/topic/enable-your-users-to-pay-per-post-or-create-your-own-advertise-on-this-site-ad-system
The system is fully functional on my site here if you want to take a look: http://etcemall.com/

The ads are custom post types and each ad size posts to specific cpt categories.
There are a limited number of ad "slots" available per size (ie per category).
Each posted ad is automatically deleted after 30 days, thus freeing up another slot.

Here's my puzzle: I'm trying to figure a way to limit the total number of posts that can be in any given category at any given time. Such that, once the limit has been reached, no new posts will be saved and, preferably, a "Sorry, not at this time" type of message can be displayed on the ad submission page.

I've Googled and Googled and scoured the WP codex for clues, but can't get a handle on this. Anyone have any cool ideas?

:slight_smile:

  • 3SixtyEvolve
    • New Recruit

    Evening @pcwriter

    Nice to find you on the other side of the thread :slight_smile:

    Not sure if this will help, but I found a post creation limits plugin called Bainternet Posts Creation Limits that might be what you're after. If not, at least you can have a look at how they've set up the plugin?

    Hope I helped :slight_smile:

    Have a good day and all the best with setting this up! You've made good progress from the looks of things [smile].

    GinaB

  • Patrick
    • Support Monkey

    Hi Gina,

    Fancy meeting you here :slight_smile:

    I looked into the Bainternet plugin at the beginning of my "quest" but, if I recall, it limits posts per user or per role. I was hoping for a way to limit the number of posts that can "active" in a given category.

    But, I suppose I could rethink my limiting strategy :slight_smile:

    Thanks for the reminder, and it is fun to find myself on this side of the thread for a while!

  • aecnu
    • WP Unicorn

    Greetings pcwriter,

    Unfortunately I do not have any solution for this at all.

    Of course time is the problem for me which also seems to be a problem for you at this time and it appears that a custom solution is in order.

    I am sorry that I cannot be of more assistance regarding this matter but will let this ticket fly for some more time to see if any other members may have a possible solution.

    Cheers, Joe

  • Mason
    • DEV MAN’s Sidekick

    Hiya pcwriter,

    Only other thing that I can think of would be to look at the post quota module in pro sites. You can use it to limit the amount of any post_type a site can create. Perhaps something there would be useful?

    Best of luck to ya as always.

  • aecnu
    • WP Unicorn

    Greetings pcwriter,

    I concur with Mason James that the only thing i am aware of that comes close to this function is the Pro Sites plugin though it is still not by category as you had mentioned.

    What threw me off in the beginning of this thread is the "Bainternet plugin" in which I have never used.

    Have you managed to come up with anything workable for limiting posts per category to date?

    Please advise.

    Cheers, Joe

  • Patrick
    • Support Monkey

    @Joe @Mason

    Nope. Haven't come up with anything useful yet. Even did a bit of research to see if the max number of table entries could be limited via phpmyadmin, but got myself more confused than informed :o)

    I'll set this as resolved for now, and reopen if anything new develops. But I may just wind up going for the solution that (the other) Joe mentioned above.

    Thanks for your time guys. Although I love puzzles, I appreciate any help I can get with some of them :o)

  • Jonathan
    • The Incredible Code Injector

    Quick Thought....

    On submission page run a check that counts how many posts in category if it is less than your desired amount return submission page or else return "Sorry, not at this time" type of message.
    Check the category widget to see how to get number posts in category :wink: and use a little bit of if else ><= and bingo :wink:

    I suck at ajax, but you could have a drop down category box that once selected would return the submission boxes, or message.

    ????

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.