Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Petros Charitopoulos
Petros Charitopoulos
21,396 Points

Wordpress theme - posts_per_page issue

Hi to all,

I am building my portfolio page, I have successfully built the project page with custom post types and custom fields and I want to display the recent project in my home page. Everything works just fine but when I am trying to limit the projects by one by adding 'post_per_page' => 1 then my home page is not being displayed at all.

Here is the code I am using:

<div id="latestProject"> <?php

$args = array(
    'post_type' => 'work'
            'posts_per_page' => 1
);
$the_query = new WP_Query( $args );

?> <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <?php get_template_part( 'content', 'work' ); ?> <?php endwhile; endif; ?> </div>

Any ideas?

Thank you.

2 Answers

Petros Charitopoulos
Petros Charitopoulos
21,396 Points

Hi Zac,

you are right there a comma missing after 'post_type' => 'work'

Thank you for your quick reply!