Skip Navigation

[Resolved] Register custom taxonomy using php

This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 6 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#606130

Tell us what you are trying to do?
I have a multi-site installation. I want to create a custom taxonomy in one (central) site using toolset-types. Than I would like to be able to copy/register these taxonomies to other sites, using my own custom plugin-code, where they will be recognized by toolset-types.

So, basically my question is: how can I register a custom taxonomy that will be recognized by toolset-types using my own custom php.
In the wp_options_(site_id) table I have seen a row with the option_name wpcf-custom-taxonomies. I imagine that this is the place where toolset stores the data for its custom-taxonomies?

Is there any documentation that you are following?
I have looked at the wordpress codex, the toolset api and looked at the types plugin code (custom-taxonomies.php). But it's a bit much to dig through it all. So if you girls/guys could help me on the way it would be great.

Thanks in advance.

Cheers, Tako

#606175

Dear Tako,

You are right, the custom taxonomy settings of Types plugin are stored in the database table "wp_options", and if you need to use custom PHP codes to register the custom taxonomy, please follow wordpress document to setup your PHP codes:
https://codex.wordpress.org/Function_Reference/register_taxonomy

There are lots of Examples in above document, for your reference.

#606425

Dear Luo Yang,

Thank you for the response. I dove a little bit deeper in the documentation and got something working.

But just to clarify a little bit more:

Imagine the following scenario.

<ol>

  • A user logges in
  • script checks what (custom) taxonomies are registered on his/her blog.
  • script checks what (custom)taxonomies are registered in a designated central blog
  • script merges these two custom taxonomies
  • script updates the (custom) taxonomies on the blog of the user
  • </ol>

    The thing is, I am not sure how to store the custom taxonomy settings in the Types "wpcf-custom-taxonomies" site option in the "wp_options" table.

    The idea is that we have a central place where can manage certain custom taxonomies that are used on various blogs throughout our network.

    This basic approach seems to work in my local dev:

    add_action('wp_login', 'lp_network_tax_manager');
    
    function lp_network_tax_manager(){
    	$source_taxonomies = get_option( 'wpcf-custom-taxonomies' );
    	switch_to_blog( get_site_option( 'lp_network_indexer_site_id' ) );
    	$destination_taxonomies = get_option( 'wpcf-custom-taxonomies' );
    	restore_current_blog();
    	$unique_taxonomies = array_merge ($source_taxonomies , $destination_taxonomies );
    	update_option('wpcf-custom-taxonomies', $unique_taxonomies  );
    }
    

    Later I could build in some checks and conditionals but for now this seems to work.
    But offcourse I don't want to mess up my database, so would you see any problems with this approach?

    Thanks for the help!

    Cheers, Tako

    #606618

    For the question:
    so would you see any problems with this approach?

    I can not see any problem, since it is a custom codes question, according to our support policy, we don't provide custom code support:
    https://toolset.com/toolset-support-policy/

    And there is a document about "How to build Toolset-based themes":
    https://toolset.com/documentation/user-guides/how-to-build-toolset-based-themes/
    you can Export the settings of all Toolset plugins, including custom taxonomy settings, and distribute it to other websites.