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

Kahlil Calavas
Kahlil Calavas
9,238 Points

Json feed code challenge

On code challenge. Look at the comment to see the output of your JSON feed. Echo out the name of the user. I echo{'name"}; and still am not passing. What am I doing wrong? What we learned was to extract out of decoded json feed with a variable such as $wptreehouse_profile yet I am not sure how to answer this without those details. here is what I have now <?php

// { // "name":"Username", // "profile_name":"profile_username", // "profile_url":"http://myapi.net/profile_username" // } echo {"name"};

?>

11 Answers

Kahlil Calavas
Kahlil Calavas
9,238 Points

echo $my_plugin_profile{'name}; worked. I only was able to guess it by looking at the second code challenge. Maybe giving users a little more data would help :) Ok off to the next challenge BTW Good job Zac. Very happy this course hit the roster.

Luke Wenke
Luke Wenke
32,294 Points

Thanks but it should actually be:

echo $my_plugin_profile->{'name'};

Kahlil Calavas
Kahlil Calavas
9,238 Points
<li><?php echo $my_plugin_profile->{'courses'}[$i]->{'name'} ?></li>

just figured out how to block code. That was the final answer I used

Ann Cascarano
Ann Cascarano
17,191 Points

Thanks for this! I was really stuck. I kept entering: <?php echo $my_plugin_profile->{'courses'}->{'name'}[$i] ?> and could not puzzle out why it wasn't working!

This worked for me:

<?php // { // "name":"Username", // "profile_name":"profile_username", // "profile_url":"http://myapi.net/profile_username" // }

echo $my_plugin_profile->{'name'} ?>

Thank you for this, I was also confused as to what variable we were accessing 'name' from.

Well now I'm stuck on challenge 2:

Is this not correct ?

<ul>
    <?php for( $i = 0; $i < count($my_plugin_profile->courses); $i++ ): ?>
        echo '<li>' . $my_plugin_profile->{'courses'}[$i]->{'name'} . '</li>';
    <?php endfor; ?>
</ul>

Keeps coming back: Bummer! You have not output the first course: "WordPress Plugin Development"

Kahlil Calavas
Kahlil Calavas
9,238 Points

I also think since you aren't technically in a php block(just inside a loop) you will also need to open up the php tag instead of just typing echo

Kahlil Calavas
Kahlil Calavas
9,238 Points

Seth I dont think you need to echo out the li

<li> <?php echo $my_plugin_profile->{'courses'}[$i]->{'name'} ?> </li>
Kahlil Calavas
Kahlil Calavas
9,238 Points

I think you technically can echo the li but the program has been set to look for the formatting taught in the project files

Kahlil,

Gah, you're correct forgot the <?php ?> block. Thank you for the feedback. </Rookie Mistakes>

Kahlil Calavas
Kahlil Calavas
9,238 Points

no problem seth. Hopefully you can download the project files in the next section. I am waiting for them to fix the project file download so I can keep going on the Plugin lesson. Im hungry to make a plugin right now I have a few great ideas.

<?php echo $my_plugin_profile->{'name'} ?>

Shai Yahav
Shai Yahav
7,153 Points

<?php echo $my_plugin_profile->{'courses'}[$i]->{'name'}; ?>