• Is it possible to restrict the number of posts filed into a taxonomy?

    For example, I have a Custom Post Type called ‘Events’, and I created a taxonomy called ‘Featured Event.’ The post filed under the ‘Featured Event’ taxonomy will be displayed on my home page. However, I want to make it so the user can only file/set ‘one’ post into the ‘Featured Event’ taxonomy.

    I’ve been looking into this issue for a while, and am clueless as to what I can do to limit the post number. Any help would be much appreciate!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi,
    from what I understand you want your users to add only one post to “Featured Event”; If this is what you want, you can set up a user meta that will count if that user has a post in “Featured Event” if he/she has, then he/she won’t have the option to post another one;
    It needs some editing, let’s first start with the story … what theme are you using? what plugin are you using for your users to create posts?
    Info about: add user meta, get user meta, update user meta
    Remember there might be other ways also this is just the way I’ll do it if I were you…
    Regards

    Thread Starter Moondrop

    (@moondrop)

    Thanks for the reply jnhghy!

    I coded the Custom Post Types/Taxonomies myself and registered them in my functions.php, and I am using a custom theme as well.

    Tracking a user’s meta seems interesting and I will look into it. The only problem about that method however is it would only restrict that particular user from filing more posts to the ‘Featured Events’ category, rather than it being universally restricted which is what I am hoping to achieve.

    well you can restrict all users this way …. it’s one future/user right?

    Thread Starter Moondrop

    (@moondrop)

    There will be multiple user accounts managing the website. If any of the users file a post into the ‘Featured Event’ category, they should all be locked out of the option to set a second ‘Featured Event.’ I’m unsure if this is possible with user meta, but if it is, that would be wonderful.

    Another idea I have, in order to restrict the number of posts filed in a category, is perhaps every time a new post is filed under ‘Featured Event’ the previous post filed under ‘Featured Event’ is un-categorized from it. How I could achieve this is also a mystery to me.

    From my point of view you can still use user meta but this would be more likely a site option, only one featured post / site.
    You can save this info in whatever table of your database you want you can use user_meta but the best practice would be to use the wp_options table.
    And to achive this you need to fallow some steps.
    one way would be to:
    Set a row in the database in wp_option table something like this:
    option_name -> active_feature;
    option_value -> no;
    autoload -> yes;

    in the page where the posts are created / they get a category, query the database where option_name = “active_feature” and get the “option_value”; if the option_value == no then you can enable the feature event category if the value is yes then that category should be not available/disabled.
    Also you need to hack the post publishing to check if the post is in the Feature Event category and if it is to change the value of “option_value” for the option_name=”active_feature”; you can do this with a hook (post_publish) that will run the code that will verify if the post is in the desired category and if it is it will change the option value.
    Hope this helps…
    Regards

    Thread Starter Moondrop

    (@moondrop)

    Hi jnhghy,

    Thank you so much for your help! For the longest time I had no idea where to even start with this functionality, but your replies have changed that and are definitely a huge help! I will check out and experiment with the method you suggested.

    Once again, thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Limiting the # of Posts Filed in a Taxonomy’ is closed to new replies.