Необходимо получить возможность добавлять дополнительные метки к статьям.
Доп таксономии. (есть множество плагинов для управления ими)
При добавлении функции, все работает и добавляется. Но при нажатии на тег, выбрасывает в 404.
Подскажите в чем может быть причина?
function create_country() {
register_taxonomy('country', 'post', array(
'hierarchical' => true,
'labels' => array(
'name' => _x( 'Страны', 'taxonomy general name' ),
'search_items' => __( 'Найти страны' ),
'all_items' => __( 'Все страны' ),
'edit_item' => __( 'Редактировать страну' ),
'update_item' => __( 'Обновить страну' ),
'add_new_item' => __( 'Добавить новую страну' ),
'new_item_name' => __( 'Название новой страны' ),
'menu_name' => __( 'Страны' ),
),
'rewrite' => array(
'slug' => 'country',
'with_front' => false,
'hierarchical' => false
),
));
}
add_action( 'init', 'create_country', 0 );
Попробуйте зайти в Настройки -> Постоянные ссылки и нажать кнопку Сохранить.
Нет. Только стандартные метки работают, дополнительные так же выбрасываtт.
Вопрос решил. убрал плагин no tag.
Теперь собственно вопрос в том, как убрать лишнее слово в url
Ооох. все под ключ сделал.
add_filter( ‘post_link’, ‘remove_parent_cats_from_link’, 10, 3 );
function remove_parent_cats_from_link( $permalink, $post, $leavename )
{
$cats = get_the_category( $post->ID );
if ( $cats ) {
// Make sure we use the same start cat as the permalink generator
usort( $cats, ‘_usort_terms_by_ID’ ); // order by ID
$category = $cats[0]->slug;
if ( $parent = $cats[0]->parent ) {
// If there are parent categories, collect them and replace them in the link
$parentcats = get_category_parents( $parent, false, ‘/’, true );
// str_replace() is not the best solution if you can have duplicates:
// myexamplesite.com/luxemburg/luxemburg/ will be stripped down to myexamplesite.com/
// But if you don’t expect that, it should work
$permalink = str_replace( $parentcats, », $permalink );
}
}
return $permalink;
}