Querying Post-Type Posts on a Single Page
URL to the page in question:
http://http://
-
Hello again Bill,
I am trying to query post-type posts on a single page and I am using the following code from the Advanced Custom Fields website with a small modification:
// args
$args = array(
'numberposts' => -1,
'post_type' => 'building_projects',
);
// query
$the_query = new WP_Query( $args );
?>
<?php if( $the_query->have_posts() ): ?>
<ul>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query();
I also created a page called page-building-projects.php. Then I created a blank page using the new page. When I viewed a page with /building_projects I got the following error message:
Not Found
We could not find the page you were looking for. You can try searching for it here:
I will appreciate your help.
Dare
Good Morning Dare,
Naming items with WordPress can cause some unusual problems when more than one item has the same slug/name.
After you create a custom post type, go to the Settings > Permalinks screen and save your permalinks again. That will flush out the permalink cache. Until that step happens, generally every instance of the custom post type will turn up a not found error.
I would also give the page where you query for the custom post type a different name/slug from the custom post type. That will help cut down on any errors there.
See if that doesn’t help out.
Have a great week,
Bill
Thanks again Bill. I think I need some patience :). I did not add the complimentary function.php code. It’s displaying nicely soon as I added the function code.
Glad you got to the bottom of it 🙂
- The topic ‘Querying Post-Type Posts on a Single Page’ is closed to new replies.