Support for custom taxonomies?

Support MB Term Meta Support for custom taxonomies?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #7181
    uxluxl
    Participant

    Hi,

    Using your plugin in a theme where we have meta boxes for categories and tags, but wondered if you have any tips/ideas how to make it work with custom taxonomies?

    For example

    $meta_boxes[] = array(
        'taxonomies' => array( 'category', 'post_tag', 'product_cat', 'product_tag' ),

    but on the users end they could have WooCommerce attribute terms such as Color which gives a taxonomy of 'pa_color' so this would work:

    $meta_boxes[] = array(
        'taxonomies' => array( 'category', 'post_tag', 'product_cat', 'product_tag', 'pa_color' ),

    but we don't know what the terms will be, so wondering is there a way to make it work for all or any taxonomy, or even if the taxonomy begins with 'pa_'?

    #7184
    Anh TranAnh Tran
    Keymaster

    Hi,

    I think you can make it work this way:

    1. Use some code to get terms from WC attribute taxonomy
    2. Put them in the meta box settings

    $terms = prefix_get_wc_attribute_terms();
    $meta_boxes[] = array(
        'taxonomies' => $terms,
    )

    I'm not sure about how to get WC attribute terms. You can do some search or ask WC team for help.

    #7189
    uxluxl
    Participant

    Hi Anh Tran,

    Thanks for your help. I think I was over complicating things.

    Realised we don't need to get the terms, only the taxonomies so this is our working example and now the user has access to custom meta boxes when they add/edit colors, sizes or whatever product attribute(s) they use.

    $taxonomy_names = array( 'category', 'post_tag', 'product_cat', 'product_tag' );
    if ( class_exists( 'WooCommerce' ) ) {
        $taxonomy_names_wc = wc_get_attribute_taxonomy_names();
        if ( $taxonomy_names_wc ) {
            $taxonomy_names = array_merge( $taxonomy_names, $taxonomy_names_wc );
        }
    }
    
    $meta_boxes[] = array(
        'taxonomies' => $taxonomy_names,
    #7192
    Anh TranAnh Tran
    Keymaster

    Ah, that's right. I was misunderstanding, too! Glad you figured it out.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Support for custom taxonomies?’ is closed to new replies.