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

PHP How to Build a WordPress Theme WordPress Theme Functions Displaying Custom Posts and Fields in a Template

Zoe Peng
Zoe Peng
10,809 Points

Can't get the content form "work"

Hello, I follow the "WordPress Development" track. Now I am "WordPress Theme Functions" >> "Displaying Custom Posts and Fields in a Template" . I do it step by step with Zac, but I can't get the title and content with "work". I only get the title with "post", anyone can help me, thanks

    <?php
    $args = array(
        'post_type' => 'work'
    );
    $the_query = new WP_Query( '$args' );
?>

<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

    <h3><?php the_title(); ?></h3>
    <?php the_field( 'description' ); ?>
    <hr>

<?php endwhile; else: ?>

    <p>No post</p>

<?php endif; ?>
Richard Duncan
Richard Duncan
5,568 Points

Could you post the exact question, is this the code on the challenge you have modified?

This might be useful http://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters

Zoe Peng
Zoe Peng
10,809 Points

hi Richard, Thank you so much. I am not doing code challenge, I follow Zac's Project step by step. But I could not get work in data like Zac. I need to provide any information would be more helpful? Thank you

1 Answer

Zoe Peng
Zoe Peng
10,809 Points

Oh~~~~~~~~ the reason is

            $the_query = new WP_Query(  $args  );

take off the single quotes !!

But I still cannot get the content... :(

Zoe Peng
Zoe Peng
10,809 Points

If I reset the paremalink, it will be OK!!!!!