Hi Biranit,
Entries should parse as normal content (they go through the the_content filter) so I’m not sure why you’re seeing that behaviour. I’m afraid I don’t have the time to debug, however if you do find the cause and fix, please let me know so I can fix it.
Thanks,
Chris Northwood
Hi Chris,
I have a feeling this has to do with the auto-embed now using the IFRAME version of youtube/vimeo/etc. It’s just a hunch.
I’ll keep investigating and let you know if I find the reason and/or the solution.
Cheers,
Bira
OK, this took a LOT of investigative work and trials and errors π
The problem is that autoembed does NOT work outside the loop. This is because it has to cache the result, or else it will need to query the embed source every time. So it has to run within the global $post.
CHRIS:
In your function live_blogging_ajax() you have a loop running, however you are using the deprecated function $q->next_post(). Changing this to $q->the_post() fixes the autoembed issue altogether, and everything works perfectly.
Not sure exactly why you use next_post() (which is, as I noted, deprecated).
Cheers,
Bira
Hi Bira,
You’ve linked to the wrong next_post there, the one that’s used is the one in here, which isn’t deprecated: http://codex.wordpress.org/Class_Reference/WP_Query. The difference between the next_post and the the_post method is that next_post doesn’t set the global loop variables, which it’s needed as technically it’s a sub loop within another loop.
Chris
OK, fair enough re the wrong link. But autoembed will not work with next_post exactly because you’re not setting the global post.
Give it a try yourself and see π
Yes, but setting the global post will break the containing loop, I think.
Nope, it does not. I did that change and evrything works flawlessly π
I’ve just tried this on a clean install and the TwentyEleven theme, and it does indeed break the containing loop (as the live blog will set the global post variable, then everything that comes after the_content in the theme will then access the global post value which contains the last live blog entry). On the TwentyEleven theme, changing the code to the_post stops comments displaying, and the entry metadata now refers to the last liveblog entry, rather than the post which contains the live blog.
Saving the post value before going into the child loop and then resetting it at the end appears to work though, so I’ve just committed that.
Chris
Chris: you’re awesome. Thank you π
Chris, just thought I’d give you a head’s up, in case anyone ever comes asking about this:
Some of my shortcodes were not working on live blogging, particularly the Blackbird Pie Twitter embed, which is actually a fantastic companion for live blogging.
I split hairs over this for three days, eventually discovering it wasn’t working because on the BBP plugin, it used if (!is_admin()) before doing add_shortcode and wp_embed_register_handler. And, since the polling uses admin-ajax.php, then obviously the is_admin() condition fails…
This has nothing to do with you, but I figured I’d let you know if someone comes asking why this-and-that isn’t working. Quite a few plugins that are geared towards frontend stuff use the !is_admin() condition, and obviously admin-ajax.php fails that. So it’s something worth keeing in mind π
Cheers,
Bira
Hi Chris,
First off, thanks for the credit in the changelog. I was floored seeing my name there! π
A couple issues with this fix, though:
1) you applied the fix (of changing next_post to the_post) to the function live_blogging_shortcode where, in fact, this was never an issue (at least not for me), because the autoembeding and other shortcodes were parsed _after_ the [liveblog] shortcode was parsed. But, I suppose it makes no harm really to have it done there too.
However, you did not apply this fix to the function live_blogging_ajax – where I ran into the issue (I use polling). (It could also be implemented in the function live_blog_chatbox_get_posts)
2) Just a suggestion: you don’t really need to store $post in an interim variable. It’s enough that you add wp_reset_postdata(); after the custom query’s loop. This restores the previous $post variable to global, but with less code π
while ($q->have_posts())
{
$q->the_post();
$r[] = array(
'liveblog' => $liveblog_id,
'id' => $q->post->ID,
'type' => 'entry',
'html' => live_blogging_get_entry($q->post)
);
}
wp_reset_postdata();
Cheers!
Bira
Credit’s due where credit’s due π
Okay, I appear to have been misunderstanding you! Of course, ajax won’t break anything as it’s not a subloop. I’ll look at fixing this.
Sorry for the bad fix!
Chris
Fixed and new version out π
Thanks again!
You’re great Chris. Thank you. Pleasure doing business with you π