Querying Post-Type Posts on a Single Page

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

This topic contains 3 replies, has 2 voices, and was last updated by  Bill Robbins 1 year, 1 month ago.

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

    Dare Adelugba
    Participant

    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

    • This topic was modified 1 year, 1 month ago by  Dare Adelugba.
    #37714

    Bill Robbins
    Moderator

    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

    #37724

    Dare Adelugba
    Participant

    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.

    #37726

    Bill Robbins
    Moderator

    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.