大多数我在网上看到的文件,query_posts不应该是去到用于创建自定义查询和回路的功能。下面的代码片段可能是一个很好的起点。您应该能够在主题模板文件的主循环内部或外部使用此内容。
$args = array(
'post_type' => 'release', //remember this is-case sensitive
'posts_per_page' => -1,
);
$releaseQuery = new WP_Query($args);
if ($releaseQuery->have_posts()) :
while ($releaseQuery->have_posts()) :
$releaseQuery->the_post();
// Fetching the post ID for demonstration and for use later
$c_id = get_the_ID();
// After running the_post(), alot of the Wordpress functions (not all) can now be used without supplying the post ID.
echo get_the_title();
// You could also have used get_the_title($c_id);
// Then:
echo get_post_meta($c_id, 'release_title', true);
echo get_post_meta($c_id, 'release_artist', true);
endwhile;
endif;
// Return to the current page's main query
wp_reset_query();
// This should now display the page's title
the_title();
是的,他们是自定义字段 - 我有那部分排序 - 我只是无法在我的网站上显示结果。 – lowercase
你究竟在做什么?您应该能够简单地在主题文件中“回显”它们。最好的办法是为这些特定的帖子类型创建一个页面(比如'single-releases。php'),你可以使用'echo get_post_meta($ post-> ID,'release_artist')''。 –
这只是不起作用。我无法弄清楚为什么。上面例子中的'ID'是动态生成的吗?还是你建议我硬编码每个人的ID? – lowercase