Как сделать так чтобы список последних записей WordPress видел только я – администратор

у меня главная на странице – это список последних записей. Как сделать так чтобы их видел только я – администратор

Решение через хук pre_get_posts в файле functions.php вашей дочерней темы

add_action( 'pre_get_posts', 'restrict_homepage_posts_to_admin' );
function restrict_homepage_posts_to_admin( $query ) {
    // Применяем только к главной странице и только к основному запросу
    if ( ! is_admin() && $query->is_main_query() && $query->is_home() ) {
        // Если пользователь не админ — делаем запрос пустым
        if ( ! current_user_can( 'administrator' ) ) {
            $query->set( 'post__in', array( 0 ) ); // Никаких постов не найдётся
        }
    }
}
guest
Другие сообщения форума
Закрыть меню
ZAPLATA.RU | Магазин готовых блогов Wordpress с автонаполнением
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.