• Hi,

    I have a field in my user profile for every author eg. restaurant, plumber, mechanic.

    Users can submit posts but I want them to only submit to the associated categories that I have created with the similar name eg. food, plumbing, mechanical.

    Is there a way to auto populate or do this in a dynamic fashion so when a user submits a post they can only post to their category ie.
    users with field “restaurant” = “food” category
    users with field “plumber” = “plumbing” category
    etc.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Yes, but it ain’t pretty!
    The first line of defense is to be sure authors do not have manage_categories capability so they cannot make up their own.

    Next is to remove the category meta box from the edit screen. Use the ‘add_meta_boxes_post’ action to remove the meta box that was just added. You cannot prevent it from being added, but it can be removed. Dig into the global $wp_meta_boxes to determine the proper ID and other parameters.

    This will result in the post being inserted with the default category, usually ‘uncategorized’. Use the ‘save_post’ action to remove that one and assign one based on the current user’s meta field. Once again, you cannot prevent the default category from being added, but you can fix things after the fact.

    You don’t actually need to remove the meta box since you are reassigning categories after the fact, but it makes for a poor user experience to offer options that are ignored. You can also hide the meta box, but users can re-enable it. The only sure way is to remove it entirely.

Viewing 1 replies (of 1 total)
  • The topic ‘auto populate category depending on user profile field’ is closed to new replies.