0

I tried creating a taxonomy using null for object type so that I can enable it for my suitable post types.

add_action( 'init', 'create_pricat' );

function create_pricat() {

$labels = array(
        'name'              => _x( 'Pricat', 'taxonomy general name', 'textdomain' ),
        'singular_name'     => _x( 'Pricat', 'taxonomy singular name', 'textdomain' ),
        'search_items'      => __( 'Search Pricat', 'textdomain' ),
        'all_items'         => __( 'All Pricat', 'textdomain' ),
        'parent_item'       => __( 'Parent Pricat', 'textdomain' ),
        'parent_item_colon' => __( 'Parent Pricat:', 'textdomain' ),
        'edit_item'         => __( 'Edit Pricat', 'textdomain' ),
        'update_item'       => __( 'Update Pricat', 'textdomain' ),
        'add_new_item'      => __( 'Add New Pricat', 'textdomain' ),
        'new_item_name'     => __( 'New Pricat Name', 'textdomain' ),
        'menu_name'         => __( 'Pricat', 'textdomain' ),
        );

    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => false,
        'publicly_queryable'    => false,
        'rewrite'               => false,
    );
}

register_taxonomy( 'pricat', null, $args );

But it got error on add_rewrite_tag() because of null object type.

Now, How do I create a taxonomy using null $object_type?

  • Why not register the taxonomy after you've registered those suitable post types? – Sally CJ Aug 1 at 13:13
  • @SallyCJ- how to do that? are you suggesting to array the post-types instead of null? – Bikram Aug 1 at 15:54
  • 1
    @Bikram That's what the docs say. $object_type can be a string, or an array for multiple post types. – Jacob Peattie Aug 2 at 0:51
  • 1
    Yes, @Bikram - register_taxonomy( 'pricat', array( 'cpt1', 'cpt2', ... ) ). And Jacob is correct, except here's the correct docs link... – Sally CJ Aug 2 at 1:46
  • 1
    Thanks, everyone. after a little bit of digging into the code, I figured that the problem was on the wrapper }... I wrapped the function before registering. The problem was on the last 2nd line from the bottom. Codes work on both on an array or null $object_type. – Bikram Aug 2 at 5:01

Your Answer

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

Browse other questions tagged or ask your own question.