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

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"

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>

Second taxonomy is not displayed in the front-end

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'
)
)
)

Get custom posts using the WP REST API

I'm trying to get custom post types, but I can not seem to find any solution. The WP REST API documentation only returns blog posts.
Note: I'm using the Dooplay theme
The code below is in the file tipo.php
directory: inc > includes > series
if( ! function_exists( 'doo_series' ) ) {
function doo_series() {
$labels = array(
'name' => _x('TV Shows', 'Post Type General Name','mtms'),
'singular_name' => _x('TV Show', 'Post Type Singular Name','mtms'),
'menu_name' => __d('TV Shows %%PENDING_COUNT_TV%%'),
'name_admin_bar' => __d('TV Shows'),
'all_items' => __d('TV Shows'),
);
$rewrite = array(
'slug' => get_option('dt_tvshows_slug','tvshows'),
'with_front' => true,
'pages' => true,
'feeds' => true,
);
$args = array(
'label' => __d('TV Show'),
'description' => __d('TV series manage'),
'labels' => $labels,
'supports' => array('title', 'editor','comments','thumbnail','author'),
'taxonomies' => array('genres'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-welcome-view-site',
'show_in_admin_bar' => true,
'show_in_nav_menus' => false,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'capability_type' => 'post',
);
register_post_type('tvshows', $args );
}
add_action('init', 'doo_series', 0 );
get_template_part('inc/includes/series/metabox');
}
Compare with
register_post_type( 'post', array(
'labels' => array(
'name_admin_bar' => _x( 'Post', 'add new from admin bar' ),
),
'public' => true,
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
'_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
'capability_type' => 'post',
'map_meta_cap' => true,
'menu_position' => 5,
'hierarchical' => false,
'rewrite' => false,
'query_var' => false,
'delete_with_user' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
'show_in_rest' => true,
'rest_base' => 'posts',
'rest_controller_class' => 'WP_REST_Posts_Controller',
) );
which registers the built in post type post. Observe the last three fields. These fields must be set to make the post type accessible via REST.
ADDENDUM
Actually only 'show_in_rest' is required as WordPress has default values for the other two. Also, if a developer wrote his own WP_REST_Controller for the custom post type instead of using the builtin WP_REST_Posts_Controller then even this is not required as his own WP_REST_Controller can call the register_rest_route() functions by some other means.

wordpress redirect to single-post.php without page_id

I'm new to wordpress and I try to do an url rewrite that looks like this
mysitename/adoption/petspecies/petname
Everything works fine until the petname part, I cannot redirect to my single-adoption.php file without hardcoding the page_id in the redirect url.
Here's how I do my custom post:
register_post_type(
'adoption',
array(
'label' => 'Adoption',
'labels' => array(
'name' => 'Adoption',
'singular_name' => 'Adoption'
),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'supports' => array(
'title',
'editor',
'thumbnail'
),
'has_archive' => true,
'rewrite' => array(
'with_front' => true,
'slug' => 'adoption',
),
)
);
register_taxonomy(
'espece',
'adoption',
array(
'label' => 'espece',
'labels' => array(
'name' => 'Espèce',
'singular_name' => 'Espèce'
),
'hierarchical' => false,
'rewrite' => array('slug' => 'adoption', 'with_front' => true)
)
);
And here's my rewrite rule
function adoption_cpt_generating_rule($wp_rewrite) {
$rules = array();
$terms = get_terms( array(
'taxonomy' => 'espece',
'hide_empty' => false,
) );
$post_type = 'adoption';
foreach ($terms as $term) {
$rules['^adoption/' . $term->slug . '/([^/]*)/?'] = 'index.php?post_type='.$post_type.'&page_id=4252&adoption=$matches[1]&name=$matches[1]';}
// merge with global rules
$wp_rewrite->rules = $rules + $wp_rewrite->rules;
}
add_filter('generate_rewrite_rules', 'adoption_cpt_generating_rule');
My code works fine with the page_id hardcoded in the redirect but stop working when I remove the page_id from the url.
Any advice to make it works without the page_id?

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.

Resources