1

I am trying to create a taxonomies attached to a custom post type. The CPT is registering fine, but the taxonomy is not showing up. Eventually there will be multiple taxonomies attached.

I am getting no errors that I can see (no fatal WP errors, nothing in the browser console) but WP is not registering the taxonomy. Its like the taxonomy class isn't even there. I checked outside of WP to see if all the values are present, and they seem to be passed correctly.

Why is it not registering? Thanks for any guidance, code below...

class pm_createTaxonomy
{
protected $textdomain;

public function __construct($textdomain)
{
    $this -> textdomain = $textdomain;

    add_action('init', array($this, 'registerTaxonomy'));
}

public function makeTaxonomy($taxName, $singularName, $pluralName, $postTypes, $settings=array())
{
    /* Cleanup slugs just in case */
    $this -> taxName = strtolower(str_replace(' ', '_', $taxName));
    $this -> postTypes = $postTypes;

    /* Default labels */
    $default_labels = array(
        'name'                       => __($pluralName, $this->textdomain),
        'singular_name'              => __($singularName, $this->textdomain),
        'search_items'               => __('Search ' . strtolower($pluralName), $this->textdomain),
        'poular_items'               => __('Popular ' . strtolower($pluralName), $this->textdomain),
        'choose_from_most_used'      => __('Choose from most used ' . strtolower($pluralName), $this->textdomain),
        'all_items'                  => __('All ' . strtolower($pluralName), $this->textdomain),
        'parent_item'                => __('Parent ' . $singularName, $this->textdomain),
        'parent_item_colon'          => __('Parent ' . $singularName, $this->textdomain),
        'edit_item'                  => __('Edit ' . $singularName, $this->textdomain),
        'update_item'                => __('Update ' . $singularName, $this->textdomain),
        'add_new_item'               => __('Add New ' . $singularName, $this->textdomain),
        'new_item_name'              => __('New ' . $singularName, $this->textdomain),
        'add_or_remove_items'        => __('Add or remove ' . strtolower($pluralName), $this->textdomain),
        'menu_name'                  => __($pluralName, $this->textdomain),
        'separate_items_with_commas' => __('Separate ' . strtolower($pluralName) . ' with commas', $this->textdomain)
    );

    $default_args = array(
        'hierarchical'      => true,
        'label'             => $pluralName,
        'labels'            => $default_labels,
        'public'            => true,
        'show_admin_column' => true,
        'show_ui'           => true,
        'show_in_nav_menus' => true,
        'rewrite'           => array('slug' => sanitize_title_with_dashes($pluralName)),
    );

    $this -> args = array_merge($default_args, $settings);
}

public function registerTaxonomy()
{
    register_taxonomy($this->taxName, $this->postTypes, $this->args);
}

}
0

Worked on this some more this evening and redid a couple of things. Edited the code above to reflect changes, everything is working now. Will mark as solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.