#html #custom-post-type #wordpress
#HTML #пользовательский тип записи #wordpress
Вопрос:
Я использую html5-blank для своей темы.
все запросы отлично работают при извлечении из стандартного типа записи WordPress… он прерывается при попытке извлечения из типа записи ‘html5-blank’.
Вот запрос:
<?php $my_query = new WP_Query('category_name=spotlightamp;showposts=2');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID; ?>
<!-- pull thumbnail image -->
<article class="article_wrap">
<div class="widget_thumb">
<a href="<?php echo get_permalink(); ?>">
<?php echo get_the_post_thumbnail(); ?>
</div>
<h1 class="widget_title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
<p class="widget_spot_description"><?php the_excerpt(); ?></p>
</article>
<?php endwhile; ?>
вот functions.php:
function create_post_type_html5()
{
register_taxonomy_for_object_type('category', 'html5-blank'); // Register Taxonomies for Category
register_taxonomy_for_object_type('post_tag', 'html5-blank');
register_post_type('html5-blank', // Register Custom Post Type
array(
'labels' => array(
'name' => __('HTML5 Blank Custom Post', 'html5blank'), // Rename these to suit
'singular_name' => __('HTML5 Blank Custom Post', 'html5blank'),
'add_new' => __('Add New', 'html5blank'),
'add_new_item' => __('Add New HTML5 Blank Custom Post', 'html5blank'),
'edit' => __('Edit', 'html5blank'),
'edit_item' => __('Edit HTML5 Blank Custom Post', 'html5blank'),
'new_item' => __('New HTML5 Blank Custom Post', 'html5blank'),
'view' => __('View HTML5 Blank Custom Post', 'html5blank'),
'view_item' => __('View HTML5 Blank Custom Post', 'html5blank'),
'search_items' => __('Search HTML5 Blank Custom Post', 'html5blank'),
'not_found' => __('No HTML5 Blank Custom Posts found', 'html5blank'),
'not_found_in_trash' => __('No HTML5 Blank Custom Posts found in Trash', 'html5blank')
),
'public' => true,
'hierarchical' => true, // Allows your posts to behave like Hierarchy Pages
'has_archive' => true,
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail'
),
'can_export' => true, // Allows export in Tools > Export
'taxonomies' => array(
'post_tag',
'category'
) // Add Category and Post Tags support
));
}
Я устанавливаю флажок категории в пользовательском типе записи, но запрос не заполняет сообщение. Он показывает только записи из стандартного типа записи.
Нееееет!
Комментарии:
1.
showposts
долгое время амортизировался!. Вы должны использоватьposts_per_page
Ответ №1:
Вы должны указать тип записи в запросе wp:
$my_query = new WP_Query('category_name=spotlightamp;posts_per_page=2amp;post_type=html5-blank');
Редактировать: заменены устаревшие showposts на posts_per_page
Комментарии:
1. Спасибо! Это работает. Чувак, у меня, должно быть, устали глаза! Итак, почему в мире этот тип записи отсутствует в основном запросе?
2.
showposts
долгое время амортизировался!. Вы должны использоватьposts_per_page