Код: Выделить всё
www.example.com/ristoranti/italia/milano/my-post-slug
Код: Выделить всё
italiaКод: Выделить всё
function mlt_create_custom_taxonomies()
{
$labels = [
'name' => _x( 'Locations', 'taxonomy general name', 'mlt' ),
'singular_name' => _x( 'Location', 'taxonomy singular name', 'mlt' ),
'search_items' => __( 'Search Locations', 'mlt' ),
'all_items' => __( 'All Locations', 'mlt' ),
'parent_item' => __( 'Parent Location', 'mlt' ),
'parent_item_colon' => __( 'Parent Location:', 'mlt' ),
'edit_item' => __( 'Edit Location', 'mlt' ),
'update_item' => __( 'Update Location', 'mlt' ),
'add_new_item' => __( 'Add New Location', 'mlt' ),
'new_item_name' => __( 'New Location Name', 'mlt' ),
'menu_name' => __( 'Location', 'mlt' ),
];
$args = [
'labels' => $labels,
'exclude_from_search' => true,
'has_archive' => true,
'hierarchical' => true,
'rewrite' => array( 'with_front' => false, 'hierarchical' => true, ),
'show_ui' => true,
'show_tagcloud' => false,
];
register_taxonomy( 'location', [ 'post' ], $args );
}
add_action('init', 'mlt_create_custom_taxonomies');
Код: Выделить всё
/%category%/%location%/%postname%/
Код: Выделить всё
function location_post_type_link( $link, $post ) {
if ('post' == $post->post_type) {
if ( $terms = get_the_terms( $post->ID, 'location' ) ) {
foreach ($terms as $term) {
$tax_array[] = $term->slug;
}
$link = str_replace( '%location%', implode('/',$tax_array), $link );
}
}
return $link;
}
add_filter( 'post_link', 'location_post_type_link', 10, 2 );
Проблема в том, что если я создам поддельный URL-адрес, например:
Код: Выделить всё
www.example.com/ristoranti/XXXXX/XXXX/my-post-slugКак это возможно? Как я могу убедиться, что таксономия в URL-адресе правильна?
Подробнее здесь: https://stackoverflow.com/questions/444 ... any-params
Мобильная версия