Ask your WordPress questions! Pay money and get answers fast! (more info)

Last page of wp_pagenavi strips out footer.php and other errors



I'm using a simple wp_query and two plugins: Advanced Custom Fields and wp_pagenavi.

For some reason the final page (5, in this case) is stripping out my footer code. I've also noticed that a stray list item is hanging around at the end of my query, but it doesn't contain any markup. Oddly enough, the first 4 generated pages of these posts display just fine. The footer shows up and there are no stray list item.

Here is the link to the problem page: [[LINK href=""]][[/LINK]]

Please help! I've pasted my template code at [[LINK href=""]]Pastebin.[[/LINK]]

Answers (3)


Jarret Minkler answers:

The problem isn't with ->format() its saying that the object, perhaps $date, is not an object. So you have to figure out why $date isn't a data object.

After the $date = ... line put in this


My guess is something is wrong in creating the date and instead of returning a date object it returns false (perhaps that post/event is missing the date?)

so, you could modify the code as

$date = DateTime::createFromFormat('Ymd', get_field( 'event_start_date' ));
if ($date) { echo '/ ' . $date->format('F d, Y'); } ?>

Other solutions would be to check all the event dates, or modify the query not to return events without the start date

'meta_value' => ' ',
'meta_compare' => '!=',

Dave Schmidt comments:

That solved it Jarret! What's bizarre is that I have a duplicate staging site that I test most of my code on, and it's working just fine. But on this live version, which is 100% identical, it doesn't work.

Regardless, you fixed it. Thank you!


Nilesh shiragave answers:

Open wp-config.php file from your websites root location and change

search for

define('WP_DEBUG', false);

and make it true

define('WP_DEBUG', true);

So we can see what errors you are getting on that page. You are getting errors after the pagination code so footer is not displaying.

Dave Schmidt comments:

I turned on the debug and turned it off since this is a test site. Here is what was returned:


Nilesh shiragave comments:

Do you have a format() function in your event class? You are getting error at line

echo '/ ' . $date->format('F d, Y');

Nilesh shiragave comments:

Just comment out that line so we can test rest of your code is working or not.


// echo '/ ' . $date->format('F d, Y');

Dave Schmidt comments:

I don't really know what a format() function is. I'm just re-using code that I've used on other sites.

Dave Schmidt comments:

It's commented out, and the page does work.

Nilesh shiragave comments:

Great.. so we have error on that function.

Please add following line just below that line which we commented out.

echo $date;

Dave Schmidt comments:

Added. Now it strips all the content out.

Nilesh shiragave comments:

how you added that?

show me your full code. also show me events code which you are using.

Dave Schmidt comments:

Here is a [[LINK href=""]]pastebin[[/LINK]] link. This is all the code in my page template. I need to sign off the computer until tomorrow. Thank you for your help, and sorry I can't stay online. I had to put the dates back in, as the site is live and the client wants to see the dates.

Thank you!

Nilesh shiragave comments:

What PHP version you have on your server? You must have PHP 5.3 +

Nilesh shiragave comments:

I think you have PHP version 5.2 on your server. Just upgrade your PHP version to 5.3 + and your problem will be solved.

Nilesh shiragave comments:

Just change time format on line

$date = DateTime::createFromFormat('Ymd', get_field( 'event_start_date' ));
echo '/ ' . $date->format('F d, Y');

Change YMD to j-M-Y like

$date = DateTime::createFromFormat('j-M-Y', get_field( 'event_start_date' ));
echo '/ ' . $date->format('F d, Y');

And your code will work and date will be displayed.

Dave Schmidt comments:

Changing the format to j-M-Y doesn't do anything.

And just confirmed that we're running PHP 5.3.

Oddly enough, when I remove the argument 'orderby' => 'meta_value_num' the errors disappear. Although, of course, the posts are not organized as we want them.


Daniel Yoen answers:

You use Custom Page for Events ?

I don't see footer code here

please check <?php wp_footer(); ?>at tha bottom of this page(events)

Daniel Yoen comments:

Depends on your error code, try to comment this line :

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