WP Custom Post Type

0

The correct one would be to have the same behavior as "Category" of post type "post" of wordpress, but this does not happen.

For example when I access http://localhost/projeto/anunciantes/ I have how to make my queries normally to customize my views, but when I access http://localhost/projeto/anunciantes/categoria/sub-categoria/enfim... it shows me error 404, even though I have left 'hierarchical' => true,

I can not understand what's happening

register_taxonomy( 'anunciante_category', array( 'anunciante' ), array(
            'hierarchical' => true,
            'label' => __( 'Categoria Anunciantes' ),
            'labels' => array( // Labels customizadas
            'name' => _x( 'Categorias', 'Categorias' ),
            'singular_name' => _x( 'Categoria', 'Categoria' ),
            'search_items' =>  __( 'Pesquisar Categorias' ),
            'all_items' => __( 'Todas Categorias' ),
            'parent_item' => __( 'Categoria Pai' ),
            'parent_item_colon' => __( 'Categoria Pai:' ),
            'edit_item' => __( 'Editar Categoria' ),
            'update_item' => __( 'Atualizar Categoria' ),
            'add_new_item' => __( 'Adicionar Nova Categoria' ),
            'new_item_name' => __( 'Nome Nova Categoria' ),
            'menu_name' => __( 'Categorias' ),
        ),
            'show_ui' => true,
            'show_in_tag_cloud' => true,
            'query_var' => true,
            'rewrite' => array(
                'slug' => 'anunciantes',//anunciantes/categorias
                'with_front' => true,
            ),
            )
        );
    
asked by anonymous 07.05.2014 / 16:38

1 answer

1
'hierarchical' => true,

Treats how pages by what I understood you would like to use as posts and their categories.

You need to put like:

'hierarchical' => false,

And create a taxonomy for this.

Something like:

// Register Custom Taxonomy
function custom_taxonomy() {

$labels = array(
    'name'                       => _x( 'Taxonomies', 'Taxonomy General Name', 'text_domain' ),
    'singular_name'              => _x( 'Taxonomy', 'Taxonomy Singular Name', 'text_domain' ),
    'menu_name'                  => __( 'Taxonomy', 'text_domain' ),
    'all_items'                  => __( 'All Items', 'text_domain' ),
    'parent_item'                => __( 'Parent Item', 'text_domain' ),
    'parent_item_colon'          => __( 'Parent Item:', 'text_domain' ),
    'new_item_name'              => __( 'New Item Name', 'text_domain' ),
    'add_new_item'               => __( 'Add New Item', 'text_domain' ),
    'edit_item'                  => __( 'Edit Item', 'text_domain' ),
    'update_item'                => __( 'Update Item', 'text_domain' ),
    'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ),
    'search_items'               => __( 'Search Items', 'text_domain' ),
    'add_or_remove_items'        => __( 'Add or remove items', 'text_domain' ),
    'choose_from_most_used'      => __( 'Choose from the most used items', 'text_domain' ),
    'not_found'                  => __( 'Not Found', 'text_domain' ),
);
$args = array(
    'labels'                     => $labels,
    'hierarchical'               => false,
    'public'                     => true,
    'show_ui'                    => true,
    'show_admin_column'          => true,
    'show_in_nav_menus'          => true,
    'show_tagcloud'              => true,
);
register_taxonomy( 'taxonomy', array( 'teste' ), $args );

}

// Hook into the 'init' action
add_action( 'init', 'custom_taxonomy', 0 );

Remembering that in the section below the word test is your CPT:

register_taxonomy( 'taxonomy', array( 'teste' ), $args );

Referencing where it will be used.

    
08.05.2014 / 14:26