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

My Theme Is Out of Control

Hello everyone,

I built a theme locally and got it in working order. Then, when I migrated everything to my live server, all hell broke loose. The weirdest part is that some pages (programs, student resources, contact) work perfectly and then others (the front page, webinars) don't. It all works locally, I'm at wit's end.

My theme should look like this.

This is the site live.

Any help would be appreciated.

8 Answers

Try changing your save date to this format: yyyymmdd

When I use this code with a static date like this, it works fine. I think it has something to do with the format of the date either in the code or in your database.

<h3><?php 
    $date = DateTime::createFromFormat( 'Ymd', '20140304' );
    echo $date->format('F j, Y'); 
?></h3>

Hi Ronal,

If you look at the source code for both the home and webinar pages, it looks like the problem is happening right after the link to the Test Event 2. It shows the source code stopping after the h3 tag. On the pages that look fine, this is not happening. I'm not sure what it is that is breaking the code, but I think that is where it is happening. Here is a snippet of what the end of the source code on the home and webinar pages looks like:

            <div class="content">
                <article class="event">


                        <h2>
                            <a href="http://center.richardtapia.net/events/test-event-2/">
                                Test Event 2                            </a>
                        </h2>
                        <h3>

Hope that helps. Good luck!

Thank you for your reply! This was also my suspicion!

However, I compared my code on the live server to that on my local one (which works) and everything is the same!

Then, the only thing I can think of is that my code for exporting the date (the part that goes in that h3) is wrong somehow? Here is my code for exporting a date picker custom field type named "date" in the string format "Month dd, yyyy":

<h3><?php 
    $date = DateTime::createFromFormat( 'Ymd', get_field( 'date' ) );
    echo $date->format('F j, Y'); 
?></h3>

I am using the plugin "Advanced Custom Fields." I thought it might have something to do with the format I'm saving the date as but it is the same format that I save it in locally. This format.

Do you see any potential errors?

Hi Ronal - Where is the get_field('date') value coming from?

On the other hand, the events page uses date picker custom field types named "start_date" and "end_date" to export the same format.

Thus, its code is:

<h3><?php

    $start_date = DateTime::createFromFormat( 'Ymd', get_field( 'start_date') );
    echo $start_date->format('F j, Y'); ?>

    <?php 

        $end = get_post_meta($post->ID, 'end_date', true);

        if ( $end ) {
            $end_date = DateTime::createFromFormat( 'Ymd', get_field( 'end_date') );
            echo " &ndash; ";
            echo $end_date->format('F j, Y');
        }
    ?>

</h3>

Both are apparently not working. Like I said before, the format that I'm saving the date in to the database is the same locally and live.

Nope, just tried it. This is such a strange error. Locally, the same code works!

I'm currently looking up where Advanced Custom Fields stores their data on my database...

Chris Dziewa
Chris Dziewa
17,781 Points

Have you made sure that you are using front page as a static front page on your wordpress admin for the live site? I could be wrong but this looks like an error with the wordpress loop. If you think it could be another error, go to your wp-config.php file at the root of your WordPress site and change WP_DEBUG from false to true so you can see your error reports.

Thank you for your reply Chris, but it is set to static front page.

Actually, Jennifer was spot on. When I delete the entire h3, everything suddenly works. Echoing get_field( 'date' ); by itself gives me a date of the format 20140304 returned from my database. So thus, the problem is not my database either.

That leaves us with DateTime::createFromFormat, whose documentation can be found here. My code appears to follow the correct semantics.

<h3><?php 
    //echo get_field( 'date' );
    $date = DateTime::createFromFormat( 'Ymd', get_field( 'date' ) );
    echo $date->format( 'F d, Y' ); 
?></h3>

It's probably a tiny mistake that is causing this huge error.

Is anyone super into date formats? Can you explain to me what I'm doing wrong?