Hello i am writing a function to modify the post content and some more information to it. But while doing this it makes the site not to load and throws a 500 Internal server error. Here is my code which i used for the hook.
add_filter("the_content","add_related_pics",1);
function add_related_pics($content){
$pics = "";
$pics.= '<ul>';
$tag = get_post_meta(get_the_ID(), 'highlight-tag', true);
$original_query = $wp_query;
$wp_query = null;
$args=array('posts_per_page'=>5, 'tag' => $tag,'orderby' => 'rand');
$wp_query = new WP_Query( $args );
if ( have_posts() ) :
while (have_posts()) : the_post();
$pics.= '<li>';
preg_match('@<img.+src="(.*)".*>@Uims', get_the_content(), $matches);
$src = $matches[1];
$pics.='<a href="'.get_permalink().'"><img src="'.$src.'" height="50" width="50" /></a>';
$pics.= '</li>';
endwhile;
endif;
$wp_query = null;
$wp_query = $original_query;
wp_reset_postdata();
$pics.='</ul>';
return $content.$pics;
}
Can anyone point that what is wrong with this code ?