1

我在 WordPress 中创建了一个名为“分类”的自定义帖子类型,并添加了一些帖子。

我可以看到下面的帖子/classifieds/post-title

但是,我正在尝试从中检索所有帖子,/classifieds但出现 404 错误。

我已按照此处的说明进行操作:

http://codex.wordpress.org/Custom_Post_Types

我使用该链接中提供的以下代码创建了一个分类页面.php:

$loop = new WP_Query( array( 'post_type' => 'classified', 'posts_per_page' => 10 ) );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo '<div class="entry-content">';
the_content();
echo '</div>';
endwhile;

但是,如果我这样写:

$loop = new WP_Query( array( 'posts_per_page' => 10 ) );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo '<div class="entry-content">';
the_content();
echo '</div>';
endwhile;

它确实显示了最新的 10 个帖子。我现在确定这一定与帖子类型本身有关。

为了确保,我已经完成了整个示例,就像这里一样:

http://codex.wordpress.org/Custom_Post_Types

即使是相同的名称,我也无法进行查询,它没有显示任何结果。

我真的很沮丧。

4

2 回答 2

1

您可以在使用 register_post_type() 函数的位置发布吗?

一个常见的错误是混淆了多个名称。检查以确保第一个参数是“分类”而不是“分类”

于 2010-06-25T05:49:46.520 回答
1

转到Settings -> Permalinks并单击Save Changes。您的重写规则将重新生成,您将不再收到 404 错误。

于 2015-03-31T15:44:47.723 回答