Wordpress переписывание URL Пользовательский пост - PullRequest
0 голосов
/ 04 апреля 2019

Привет, у меня есть собственное название поста "поездки", в котором есть формат URL www.domain.com/trips/tripname/

Я хочу удалить из URL базовое имя типа поездок "trips", а также добавить имя texonomy (название страны) в URL, как это www.domain.com/countryname/tripname/

$labels5 = array(
        'name'               => _x( 'Trips', 'post type general name', 'your-plugin-textdomain' ),
        'singular_name'      => _x( 'Trip', 'post type singular name', 'your-plugin-textdomain' ),
        'menu_name'          => _x( 'Trips', 'admin menu', 'your-plugin-textdomain' ),
        'name_admin_bar'     => _x( 'Trips', 'add new on admin bar', 'your-plugin-textdomain' ),
        'add_new'            => _x( 'Add New', 'client', 'your-plugin-textdomain' ),
        'add_new_item'       => __( 'Add New item', 'your-plugin-textdomain' ),
        'new_item'           => __( 'New item', 'your-plugin-textdomain' ),
        'edit_item'          => __( 'Edit item', 'your-plugin-textdomain' ),
        'view_item'          => __( 'View item', 'your-plugin-textdomain' ),
        'all_items'          => __( 'All', 'your-plugin-textdomain' ),
        'search_items'       => __( 'Search', 'your-plugin-textdomain' ),
        'parent_item_colon'  => __( 'Parent', 'your-plugin-textdomain' ),
        'not_found'          => __( 'No item found.', 'your-plugin-textdomain' ),
        'not_found_in_trash' => __( 'No item found in Trash.', 'your-plugin-textdomain' )
    );

    $args5 = array(
        'labels'             => $labels5,
        'description'        => __( 'Description.', 'your-plugin-textdomain' ),
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array('slug' => '/'), 
        'capability_type'    => 'post',
        'has_archive'        => false,
        'hierarchical'       => false,
        'menu_position'      => null,
        'taxonomies'          => array('destination','kontinent','triptype','tripform','travel-time'),
        'supports'           =>  array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
        'menu_icon'         => 'dashicons-businessman',
    );

    register_post_type('trips', $args5);


add_filter( 'post_type_link','custom_post_type_link',10,3);
function custom_post_type_link($permalink, $post, $leavename) {
    if (!gettype($post) == 'post') {
        return $permalink;
    }
    $tdest = '';
    $trip_destination = get_the_terms($post->ID, 'destination');
    if($trip_destination){
        $tdest = $trip_destination[0]->slug;
    }
    switch ($post->post_type) {
        case 'trips':
            if(!empty($tdest)){
                $permalink = get_home_url() . '/'.$tdest.'/' . $post->post_name . '/';
            } 

            break;
    }

    return $permalink;
}

Любая помощь будет оценена

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...