Поддержка Проблемы и решения url для кастомного типа материала. удалить slug

  • Добрый вечер! Есть кастомный тип материала products_type, так вот слаг самого кастомного типа материала надо убрать из url.. пробовал делать как люди в google предлагают

    function remove_slug( $post_link, $post, $leavename ) {
    if ( 'products_type' != $post->post_type || 'publish' != $post->post_status ) {
    return $post_link;
    }
    $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
    return $post_link;
    }
    add_filter( 'post_type_link', 'remove_slug', 10, 3 );
    
    function custom_parse_request_tricksy( $query ) {
    
        // Only noop the main query
        if ( ! $query->is_main_query() )
            return;
    
        // Only noop our very specific rewrite rule match
        if ( 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) {
            return;
        }
    
        // 'name' will be set if post permalinks are just post_name, otherwise the page rule will match
        if ( ! empty( $query->query['name'] ) ) {
            $query->set( 'post_type', array( 'post', 'products_type', 'page' ) );
        }
    }
    add_action( 'pre_get_posts', 'custom_parse_request_tricksy' );

    ссылки получаются как надо, но выдает 404 ошибку а записи доступны по старому url. Также ставил такой плагин Remove slug from custom post type — все один в один как и в первом случае.

Просмотр 2 ответов — с 1 по 2 (всего 2)
Просмотр 2 ответов — с 1 по 2 (всего 2)
  • Тема «url для кастомного типа материала. удалить slug» закрыта для новых ответов.