Second taxonomy is not displayed in the front-end - wordpress

i had created two taxonomies with register_taxonomy() with same settings
register_taxonomy(
'books',
'books',
array(
'label' => __( 'Kategorie' ),
'rewrite' => array( 'slug' => 'books' ),
'hierarchical' => true,
'show_admin_column' => true,
'show_ui' => true,
'capabilities' => array(
'manage_terms' => 'manage_books',
'edit_terms' => 'edit_books',
'delete_terms' => 'delete_books',
'assign_terms' => 'assign_books',
)
)
);
register_taxonomy(
'genre',
'genre',
array(
'label' => __( 'Tag' ),
'rewrite' => array( 'slug' => 'genre' ),
'hierarchical' => true,
'show_admin_column' => true,
'show_ui' => true,
'capabilities' => array(
'manage_terms' => 'manage_genre',
'edit_terms' => 'edit_genre',
'delete_terms' => 'delete_genre',
'assign_terms' => 'assign_genre',
)
)
);
If i want to display the terms for books it works but if i want to display the genre taxnomie, i get a null statement.
$books = get_the_terms( $id, 'books');
=> Get all Tags
$genre = get_the_terms( $id, 'genre');
=> Get NULL without any values

You need to add in default capabilities instead of 'manage_genre' to 'manage_categories' same for others, please check below code
register_taxonomy( 'genre',
'genre',
array(
'label' => __( 'Tag' ),
'rewrite' => array( 'slug' => 'genre' ),
'hierarchical' => true,
'show_admin_column' => true,
'show_ui' => true,
'capabilities' => array(
'manage_terms' => 'manage_categories',
'edit_terms' => 'manage_categories',
'delete_terms' => 'manage_categories',
'assign_terms' => 'edit_posts'
)
)
)

Related

Export Wordpress Custom post type Data CSV from Front-end

Please help me. I'm new to WordPress and creating a custom posts. Export WordPress Custom post type Data CSV, XML, and pdf from the Front-end button.
Please help me. I'm new to WordPress and creating a custom posts. Export WordPress Custom post type Data CSV, XML, and pdf from the Front-end button.
here is my current code:-
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type('servicelist',
array(
'labels' => array(
'name' => __( 'Service-Details' ),
'singular_name' => __( 'Service - Detail' ),
'add_new' => 'Add Service',
'all_items' => 'All Service'
),
'description' => __( 'Service Details' ),
'public' => true,
'hierarchical' => true,
'has_archive' => true,
'supports' => array(
'title',
'thumbnail',
'custom-fields',
'page-attributes'
),
'show_in_menu' => true,
'menu_icon' => 'dashicons-visibility',
'menu_position' => 20
));
register_taxonomy('division', 'servicelist',
array(
'hierarchical' => false,
'label' => __('Division'),
'query_var' => 'division',
'rewrite' => array('slug' => 'division' )
));
register_taxonomy('district', 'servicelist',
array(
'hierarchical' => false,
'label' => __('District'),
'query_var' => 'district',
'rewrite' => array('slug' => 'district' )
));
register_taxonomy('upazila', 'servicelist',
array(
'hierarchical' => false,
'label' => __('Upazila'),
'query_var' => 'upazila',
'rewrite' => array('slug' => 'upazila' )
));
register_taxonomy('service-type', 'servicelist',
array(
'hierarchical' => false,
'label' => __('Service type'),
'query_var' => 'service-type',
'rewrite' => array('slug' => 'service-type' )
));
}
<span id="ex" class="ng-binding">Export</span>

Invalid Taxonomy Wordpress

I have created a custom taxonomy which is working fine. Below are the code:
add_action('init', 'canderel_game_taxonomy', 0);
function canderel_game_taxonomy() {
$labels = array(
'name' => 'Gamme',
'singular_name' => 'Gamme',
'search_items' => 'Recherche Gamme',
'all_items' => 'Toutes les Gammes',
'parent_item' => 'Gamme Parent',
'parent_item_colon' => 'Gamme Parent',
'edit_item' => 'Editer Gamme',
'update_item' => 'Enregistrer Gamme',
'add_new_item' => 'Nouvelle Gamme',
'menu_name' => 'Gammes'
);
register_taxonomy('gammes', array('produit'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'public' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'gamme' ),
));
}
Here is my code to fetch the taxonomy term but it is returning invalid taxonomy everytime.
$terms = get_terms([
'taxonomy' => 'gammes',
'hide_empty' => false,
]);

Rewrite Custom Post Type(with taxonomies) URL

I have a Custom Post Type with 1 taxonomy and this is the link structure:
mywebsite.com/casos-legal (Show the post in archive-casos-legal.php)
And when I click on any post:
mywebsite.com/casos-legal/lima/this-is-the-post-title
In the case above, "lima" is a term of the taxonomy.
Is there a way to add a path before "casos-legal"? something like this:
mywebsite.com/temas/legal/casos-legal
and:
mywebsite.com/temas/legal/casos-legal/lima/this-is-the-post-title
And much better, change the post slug for just "casos" to get something like this:
mywebsite.com/temas/legal/casos/lima/this-is-the-post-title
Thank in advance!
This is how it looks the CTP
function aprodeh_casos(){
$labels = array(
'name' => 'Casos - legal',
'singular_name' => 'Caso',
'add_new' => 'Agregar',
'all_items' => 'Todos',
'add_new_item' => 'Agregar',
'edit_item' => 'Editar',
'new_item' => 'Nuevo',
'view_item' => 'Ver',
'search_item' => 'Buscar',
'not_found' => 'No se encontraron casos',
'not_found_in_trash' => 'No se encontraron casos en la papelera',
'parent_item_colon' => 'Parent Item',
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'query_var' => true,
'rewrite' => array( 'slug' => '/casos-legal/%categoria_casos%', 'with_front' => false ),
'has_archive' => 'casos-legal',
'capability_type' => 'post',
'hierarchical' => false,
'supports' => array(
'title',
'editor',
'thumbnail',
),
'menu_position' => 5,
'exclude_from_search' => false,
'taxonomies' => array('post_tag'),
);
register_post_type('casos-legal',$args);
} add_action('init','aprodeh_casos');
This is how it looks the Taxonomy:
function aprodeh_casos_taxonomia(){
$labels = array(
'name' => 'Categorías',
'singular_name' => 'Categoría',
'search_items' => 'Buscar categoría',
'all_items' => 'Todas las categorías',
'edit_item' => 'Editar categoría',
'update_item' => 'Actualizar categoría',
'add_new_item' => 'Agregar categoría',
'new_item_name' => 'Nuevo categoría',
'menu_name' => 'Categorías',
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'casos-legal', 'with_front' => false ),
);
register_taxonomy('categoria_casos', array('casos-legal'), $args);
}
add_action('init', 'aprodeh_casos_taxonomia');
And finally, this code in order to get this link structure:
mywebsite.com/casos-legal/lima/this-is-the-post-title
function wpa_casos_permalinks( $post_link, $post ){
if ( is_object( $post ) && $post->post_type == 'casos-legal' ){
$terms = wp_get_object_terms( $post->ID, 'categoria_casos' );
if( $terms ){
return str_replace( '%categoria_casos%' , $terms[0]->slug , $post_link );
}
}
return $post_link;
}
add_filter( 'post_type_link', 'wpa_casos_permalinks', 1, 2 );
Try updating
'rewrite' => array( 'slug' => '/casos-legal/%categoria_casos%', 'with_front' => false ),
to
'rewrite' => array( 'slug' => '/tema/legal/casos/%categoria_casos%', 'with_front' => false ),

Registering custom post type wordpress

I have created new post type in my theme but when i try to get to the permalink for the post, it give me that the post not found
function my_post_type_news() {
register_post_type( 'news',
array(
'label' => __('News'),
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'menu_position' => 5,
'rewrite' => array(
'slug' => 'news',
'with_front' => FALSE,
),
'supports' => array(
'title',
'thumbnail',
'editor',
'excerpt')
)
);
register_taxonomy('news_category', 'news', array('hierarchical' => true, 'label' => 'News Categories', 'singular_name' => 'Category', "rewrite" => true, "query_var" => true));
}
add_action('init', 'my_post_type_news');
function my_post_type_news() {
register_post_type( 'news',
array(
'label' => __('News'),
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'menu_position' => 5,
'rewrite' =>false,
'supports' => array(
'title',
'thumbnail',
'editor',
'excerpt')
)
);
register_taxonomy('news_category', 'news', array('hierarchical' => true, 'label' => 'News Categories', 'singular_name' => 'Category', "rewrite" => true, "query_var" => true));
}
add_action('init', 'my_post_type_news');
Use above function, it will works. I have changed rewrite as false.
Hope it helps.

Custom taxonomy "hierarchical' => true" not working in WordPress 2.8

Another WordPress issue from me!
I've been trying to set up two custom taxonomies in WordPress 2.8 for "Course subject" and "Type of opportunity".
I used this code in functions.php:
function create_pc_db_taxonomies() {
register_taxonomy( 'course', 'post', array(
'hierarchical' => false,
'label' => __('Course subject', 'series'),
'query_var' => 'course',
'rewrite' => array( 'slug' => 'courses' )
) );
register_taxonomy( 'type', 'post', array(
'hierarchical' => false,
'label' => __('Type of opportunity', 'series'),
'query_var' => 'type',
'rewrite' => array( 'slug' => 'types' )
) );
}
which works absolutely fine, but I want hierarchical (category-style) admin boxes rather than tag-style admin boxes.
However, when I set 'hierarchical' => true so that the above code becomes:
function create_pc_db_taxonomies() {
register_taxonomy( 'course', 'post', array(
'hierarchical' => true,
'label' => __('Course subject', 'series'),
'query_var' => 'course',
'rewrite' => array( 'slug' => 'courses' )
) );
register_taxonomy( 'type', 'post', array(
'hierarchical' => true,
'label' => __('Type of opportunity', 'series'),
'query_var' => 'type',
'rewrite' => array( 'slug' => 'types' )
) );
}
I get no boxes at all.
Am I doing something wrong?
It's working but there isn't any admin UI automatically built in WP-Admin, according to Trac "Support will be added later"

Resources