Свой тип записи
Дорабатываю сайт, делаю новый раздел, как обычно создаю новый тип записи
add_action('init', 'init_post_type'); function init_post_type() { register_post_type('experts', array( 'public' => true, 'supports' => array('title', 'excerpt', 'thumbnail'), 'labels' => array( 'name' => 'Эксперты', 'all_items' => 'Все', 'add_new' => 'Добавить нового' ) )); }
Вывожу записи
<?php $experts = new WP_Query(array('post_type' => 'experts', 'posts_per_page' => -1, 'order' => 'ASC')); ?> <?php while ($experts->have_posts()) : $experts->the_post(); ?> <div class="personal"> <?php the_post_thumbnail('experts'); ?> <div class="name"><?php the_title(); ?></div> <div class="profession"><?php the_excerpt(); ?></div> <div class="wrap-btn"><a href="<?php the_permalink(); ?>" class="btn">Получить <br /> консультацию</a></div> </div> <?php endwhile;?>
потом задаю шаблон для отображения записи
add_filter( 'template_include', 'include_template_function', 1 ); function include_template_function( $template_path ) { if ( get_post_type() == 'experts' ) { if ( is_single() ) { if ( $theme_file = locate_template( array ( 'experts_single.php' ) ) ) { $template_path = $theme_file; } else { $template_path = plugin_dir_path( __FILE__ ) . '/experts_single.php'; } } } }
когда перехожу по ссылке записи, то кидает на главную страницу.
Попробовал посмотреть глобальную переменную global $post; она пустая
не могу понять в чем проблема.
Забыли return $template_path;
Создайте single-experts.php в теме. Подобное работает даже без подключение темплейта, согласно иерархии
Вообщем я давно уже нашел решение, не знал, что вордпресс все ссылки для типов данных кэширует, и надо их обновлять в настройках