Querying Post-Type Posts on a Single Page

Support Area Forums Foundation Querying Post-Type Posts on a Single Page

Viewing 4 posts - 1 through 4 (of 4 total)
URL to the page in question: http://http://
  • Author
  • #37711
    Dare Adelugba

    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() ): ?>
    	<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
    			<a href="<?php the_permalink(); ?>">
    				<?php the_title(); ?>
    	<?php endwhile; ?>
    <?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.


    Bill Robbins

    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,

    Dare Adelugba

    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.

    Bill Robbins

    Glad you got to the bottom of it 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Querying Post-Type Posts on a Single Page’ is closed to new replies.