• I haven’t had any luck finding others who’ve asked this, but I can’t imagine nobody has. I’ll try to be as descriptive as possible!

    I am implementing a site which allows users to create new “Projects”, which I’m storing as custom Page types.

    I have a few other custom post types called “Events” and “Grants” which I’d like users to be able to associate with zero or more Projects, similar to WordPress’s tagging/categorization system.

    My problem is that I want the “projects” taxonomy to be dynamically populated or synchronized with the existing Project pages, so if the user adds a new Project page, it will automatically reflect as an option in the “Projects” taxonomy for new Events and Grants.

    I don’t really want any users to be able to customize the Project taxonomy manually. I’d prefer the only way for it to change is by adding, removing, or editing Project pages.

    Any thoughts on what I’m trying to accomplish here?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi

    let me rephrase to see if I have understood

    when someone saves (or maybe rather ‘publishes’ ) a post, you want a taxonomy term created that relates to that page – maybe the term is the slug of that page? (probably a variation of the slug rather to avoid permalink confusion )

    So add a custom function to the “publish_post” action
    http://codex.wordpress.org/Plugin_API/Action_Reference#Post.2C_Page.2C_Attachment.2C_and_Category_Actions

    function then gets the project post details and creates a taxonomy term
    and inserts that.
    See
    http://codex.wordpress.org/Function_Reference/wp_insert_term

    Thread Starter adamnationx

    (@adamnationx)

    You have exactly the right idea.

    I am very new to WordPress, so I figured I’d try to ask some experts about the correct way to approach this. It seems like this shouldn’t be the first time somebody wanted to be able to do such a thing.

    I’m also concerned about breaking the core or future plugins that may get installed. Is doing something like this relatively safe?

    Additionally, I need to keep the terms list synchronized, which means I can’t just hook into publish_post, but will also need to capture edits (to handle name changes) and deletes. Foresee any problems here?

    I’ll obviously need to figure out a naming convention for these terms, and I’ll need to ensure that they don’t get duplicated on create or edit.

    I think I’m covering all my bases here. Any thoughts?

    Well I am not sure that what you are trying to do makes functional sense, but you are unlikely to break wp using it as wp is intended to be used.

    You say you do not want people to customise the taxonomy manually but are then going to somehow programmatically create taxonomy terms from what they enter anyway … so in a sense they are defining the new terms anyway?

    So is there a 1-1 between taxonomy term and project? So you just want the taxonomy functionality to be able to be used for the other posts types, maybe query widgets etc.

    Essentialy Yes safe – so long as you do not deliberately do something that would break it – wp is intended to be extended via the use of actions and filters and it pays off (as in your code will be less likey to break with wordpress upgrades) to use the provided functions.

    There are edit and delete hooks too. You’ll just have to make sure that your code is thorough and consistent.

    If new to wordpress then you may find the professional wordpress plugin development book very useful (and/or the beginners one). While most of wordpress info is freely available and here on the codes, it can take a while to find it/ gather it together and the pro book in particular I found to be a good wrapup – I knew mots of the stuff already, but nonethless learnt a few things – it is well structured and has code examples you can download. More details/links on both books here:

    http://wppluginmarket.com/16109/professional-wordpress-plugin-development/

    Hi @adamnationx, this is EXACTLY what I’m looking to do. Did you ever have any luck figuring this out? I’ve figured out how to create a new term when a post is published, but not how to “sync” the term with the post i.e. edit the term name when the post title changes or delete the term if the post is deleted.

    Any help is greatly appreciated, thanks!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Synchronizing a taxonomy with a list of pages’ is closed to new replies.