WP Custom Post Type

Asked

Viewed 197 times

0

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

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

I can’t 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,
            ),
            )
        );

1 answer

1

'hierarchical' => true,

Treats as pages by what I understand you would like to use as a post and its categories.

You need to put as:

'hierarchical' => false,

And create a taxonomy for that.

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 excerpt the word test is your CPT:

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

Thus referencing where it will be used.

  • this is exactly how is my current function for custom post type http://pastebin.com/kKgPTyQJ I am analyzing what you answered me

  • tries to leave different CPT and taxonomy nomenclature, generates less work debugging problems.

  • but CPT is advertiser and TAXONOMY is advertiser_category

  • 'hierarchical' => true, needs to be false because true equals page and false equals post

  • I tested with the false, but from what I’ve seen need to leave true for him to follow the categories daughters

  • and another if I leave as 'hierarchical' => false is everything as parent category, and that’s not what I intend

  • by what I read false is like post where it works straight and true as pages

  • the point is that none of the ways works as it has to, but when the value is set true it turns everything into parent category, and that is not valid

  • If it is more practical https://wordpress.org/plugins/custom-post-type-ui/

  • I am avoiding the unnecessary use of plugins, but if I can’t make it work otherwise, I check the possibility of using it

  • http://pastebin.com/MKicRBPh

  • This is a test

  • I haven’t found a solution yet ... it works inappropriately

  • which would be inappropriate ?

  • my advertising taxonomy_category does not work like the categories of posts for example

  • very strange that there yesterday I needed and I ended up creating the same way I passed you and this working normally

  • Have you seen my complete Pastebin ? http://pastebin.com/kKgPTyQJ code :/

  • Both are equal and can generate the whole error

Show 13 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.