Question

I've created a custom post type in WordPress called 'classifieds' and added a few posts.

I can see the posts under /classifieds/post-title

However, I am trying to retrieve all posts from /classifieds but I am getting a 404 error.

I've followed instructions here:

http://codex.wordpress.org/Custom_Post_Types

and I created a classifieds-page.php with the following code provided in that link:

$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;

However, if I write this:

$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;

it does shows the latest 10 posts. I am sure now that this must be something related to the post type itself.

To make sure, I have done the whole example just like in here:

http://codex.wordpress.org/Custom_Post_Types

even the same names and I am not able to make the query, it shows no results.

I'm really frustrated.

Was it helpful?

Solution

Go to Settings -> Permalinks and click on Save Changes. Your rewrite rules will be regenerated and you won't get a 404 error anymore.

OTHER TIPS

Can you post where you use the register_post_type() function?

One common error is to mix up the plurality of the name. Check to make sure the first parameter is 'classified' rather than 'classifieds'

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top