Rest-Easy
Rest-Easy copied to clipboard
rez_serialize_post causing 502 server error
I have a shortcode in the wp-content of this post: http://bernards.local/careers/employment/. This page loads fine.
If I request the parent page (http://bernards.local/careers/) it will cause a 502 error and not load the page.
The first line in the foreach() loop seems to cause the error.
foreach($pages as $parent_page) {
$output[$index] = apply_filters('rez_serialize_post', $parent_page); // This breaks the server
$output[$index]['related']['children'] = array();
// Now add children
$args = array(
'post_type' => 'page',
'orderby' => 'menu_order',
'posts_per_page' => -1,
'post_parent' => $parent_page->ID,
'order' => 'ASC'
);
$children = get_posts($args);
foreach($children as $child) {
$output[$index]['related']['children'][] = apply_filters('rez_serialize_post', $child); // This breaks the server
}
$index++;
}
Finding out that even when visiting http://bernards.local/careers/ the shortcode is running, so this is generating an infinite loop.
So the issue was that the shortcode was running on any parent URL, and because the shortcode did a get children loop off global $post, it would become an infinite loop.
Not sure exactly why it's running the shortcode on every URL (and using the $post that goes with that URL), I suspect because apply_filters('the_content', $target_post->post_content) line in rez_serialize_post is opening up the shortcodes, which is causing the loop? Or perhaps its the use of setup_postdata() in rez_serialize_post? That is actually probably not needed anyway...