• Resolved CarolineElisa

    (@carolineelisa)


    I have successfully added other PHP snippets, but the following code is not creating the ‘Brand’ taxonomy:

    add_action( 'init', 'my_brands_register_taxonomy', 0 );
    function my_brands_register_taxonomy() {
    $labels = array(
    'name' => _x( 'Brand', 'taxonomy general name', 'deliboutique' ),
    'singular_name' => _x( 'Brand', 'taxonomy singular name', 'deliboutique' ),
    'search_items' => __( 'Search Brands', 'deliboutique' ),
    'popular_items' => __( 'Popular Brands', 'deliboutique' ),
    'all_items' => __( 'All Brands', 'deliboutique' ),
    'parent_item' => null,
    'parent_item_colon' => null,
    'edit_item' => __( 'Edit Brand', 'deliboutique' ),
    'update_item' => __( 'Update Brand', 'deliboutique' ),
    'add_new_item' => __( 'Add New Brand', 'deliboutique' ),
    'new_item_name' => __( 'New Brand Name', 'deliboutique' ),
    'separate_items_with_commas' => __( 'Separate Brands with commas', 'deliboutique' ),
    'add_or_remove_items' => __( 'Add or remove Brands', 'deliboutique' ),
    'choose_from_most_used' => __( 'Choose from the most used Brands', 'deliboutique' ),
    'menu_name' => __( 'Brands', 'deliboutique' ),
    );
    register_taxonomy('brands','product',array(
    'hierarchical' => false,
    'labels' => $labels,
    'show_ui' => true,
    'show_admin_column' => true,
    'update_count_callback' => '_update_post_term_count',
    'query_var' => true,
    'rewrite' => array( 'slug' => 'brand' ),
    ));
    }

    The same code dropped into the functions.php file creates the taxonomy.

    • This topic was modified 1 year, 10 months ago by CarolineElisa. Reason: Meant to say taxonomy, not CPT
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @carolineelisa,

    The code you shared is for registering a new taxonomy, it’s using the register_taxonomy function. I’m not sure how it works in functions.php but there might be more code there?

    If you wish to create new custom post type with WPCode, the easiest way is to use the built-in code generator. Simply go to wp-admin > Code Snippets > Generator and choose the Post Type generator: https://a.supportally.com/i/4sWMSR

    That will give you a form where you can fill in the CPT details and then save that as a new snippet.
    You can even use the same form to make changes later without having to edit the code manually.

    Let me know if that helps.

    Thread Starter CarolineElisa

    (@carolineelisa)

    Thanks @gripgrip

    I meant to say taxonomy, not CPT. Oops! I have edited question

    I tried the generator for creating a taxonomy and it also didn’t work

    • This reply was modified 1 year, 10 months ago by CarolineElisa.
    Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @carolineelisa,

    OK, thank you for the update, I have tried the code on my end and I can see it’s registered correctly and it shows up in the “Products” submenu.

    Are you using the “Run Everywhere” auto-insert location for this snippet?

    Thread Starter CarolineElisa

    (@carolineelisa)

    So it turns out the issue was due to a syntax error in another snippet

    Thanks so much for your time @gripgrip!

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

The topic ‘Custom taxonomy not created, same code works fine in functions.php’ is closed to new replies.