N
N
Nikolay2018-03-11 15:50:55
WordPress
Nikolay, 2018-03-11 15:50:55

Why are “pretty links” for scheduled posts lost?

I get the required records by request

get_posts([
    'numberposts' => 12,
    'post_type'   => 'courses',
    'post_status' => 'publish, future',
    'orderby'     => 'date',
    'order'       => 'ASC',
]);

I use the function to display the link the_permalink().
If you specify the date of the entry in the "past" - then it is displayed as http://wordpress.test/courses/призма-как-галактика.
And if you specify the future - then http://wordpress.test/?post_type=courses&p=102, but if you "manually" enter it in the address bar of the browser http://wordpress.test/courses/призма-как-галактика, then the page opens correctly.
The latest version of WordPress is 4.9.4.
The permalink settings say "Post Name" ( http://wordpress.test/sample-post/)
The .htaccess file is missing.
There are no plugins, modifications have added their own post types and taxonomies:
Code in functions.php
if (!function_exists('courses_cp')) {
    function courses_cp() {
        $labels = array(
            'name'                => _x( 'Курсы', 'Post Type General Name', 'courses' ),
            'singular_name'       => _x( 'Курсы', 'Post Type Singular Name', 'courses' ),
            'menu_name'           => __( 'Курсы', 'courses' ),
            'parent_item_colon'   => __( 'Родительский:', 'courses' ),
            'all_items'           => __( 'Все курсы', 'courses' ),
            'view_item'           => __( 'Просмотреть', 'courses' ),
            'add_new_item'        => __( 'Добавить новую запись в Курсы', 'courses' ),
            'add_new'             => __( 'Добавить', 'courses' ),
            'edit_item'           => __( 'Редактировать запись', 'courses' ),
            'update_item'         => __( 'Обновить запись', 'courses' ),
            'search_items'        => __( 'Найти запись', 'courses' ),
            'not_found'           => __( 'Не найдено', 'courses' ),
            'not_found_in_trash'  => __( 'Не найдено в корзине', 'courses' ),
        );
        $args = array(
            'labels'              => $labels,
            'supports'            => array( 'title', 'editor', 'excerpt', ),
            'taxonomies'          => array( 'courses_tax' ),
            'public'              => true,
            'menu_position'       => 5,
            'menu_icon'           => 'dashicons-book-alt',
        );
        register_post_type('courses', $args);
    }

    add_action('init', 'courses_cp', 0);
}
if (!function_exists('courses_tax')) {
    function courses_tax() {
        $labels = array(
            'name'                       => _x( 'Категории Курсов', 'Taxonomy General Name', 'courses'),
            'singular_name'              => _x( 'Категория Курса', 'Taxonomy Singular Name', 'courses'),
            'menu_name'                  => __( 'Категории', 'courses' ),
            'all_items'                  => __( 'Категории', 'courses' ),
            'parent_item'                => __( 'Родительская категория Курса', 'courses' ),
            'parent_item_colon'          => __( 'Родительская категория Курса:', 'courses' ),
            'new_item_name'              => __( 'Новая категория', 'courses' ),
            'add_new_item'               => __( 'Добавить новую категорию', 'courses' ),
            'edit_item'                  => __( 'Редактировать категорию', 'courses' ),
            'update_item'                => __( 'Обновить категорию', 'courses' ),
            'search_items'               => __( 'Найти', 'courses' ),
            'add_or_remove_items'        => __( 'Добавить или удалить категорию', 'courses' ),
            'choose_from_most_used'      => __( 'Поиск среди популярных', 'courses' ),
            'not_found'                  => __( 'Не найдено', 'courses' ),
        );
        $args = array(
            'labels'                     => $labels,
            'hierarchical'               => true,
            'public'                     => true,
        );
        register_taxonomy('courses_tax', array('courses'), $args);
    }
    add_action('init', 'courses_tax', 0);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2018-03-13
@iNickolay

Nicholas , None. And this is not a strange decision, as it should be. I suspect you are not using this function correctly. Future date, also known as scheduled post, is an unpublished entry, which means it does not yet have a URL, and it is not available to users, it is not displayed on the site. That is, by default it should not be displayed on the site, that's not what it was made for. It will be published when the desired date arrives, and then it will have a public URL. In your case, you are trying to "trick the system" by forcibly requesting posts that have not yet been published.
I would venture to suggest that you want to make some kind of announcement of future materials, for example, this happens with events. In this case, the problem is solved in a different way - create a custom field for the records with the required date, and operate on the values ​​of this field. With a WP_Meta_Query subquery, get "old posts" that have a meta field <= current date, and "future posts" that have a value >= current date. Wherever you have the date (by default, the publication date), change it to the data from the meta field. In this case, all entries - both old and "future" will have the status of publish, public URL and all that. But you can display them as your heart pleases.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question