title: 500 internal server error jQuery and WordPress
body: <p>I am attempting to use ajax in my WordPress project to dynamically load videos depending on their post ID. At the moment when I click on the video link I get the error 500 internal server error. I send the post ID via ajax to a PHP script, there I attempt to get the post meta of the post using the ID and then display the video url stored within that post meta. Can anyone see where I am going wrong?</p>
  
  <p>Below is my shortcode function</p>
  
  <pre><code>/**
       * Render the HTML code for the  speaker interviews
       *
       * @return $output string The HTML code to be rendered, caught by ob_start();
       */
  
      function test_view_shortcode_fn( $attributes ) {
  
          ob_start();
  
          $args = array( 'post_type' =&gt; 'test_video',
                                         'post_status' =&gt; 'publish',
                                         'posts_per_page' =&gt; 1
                                         );
  
          $main_video = new WP_Query( $args );
  
          if( $main_video-&gt;have_posts() ) : while ( $main_video-&gt;have_posts() ) : $main_video-&gt;the_post(); 
  
  
          $video = get_post_meta( get_the_ID(), '_video_url' );
          $poster = get_post_meta( get_the_ID(), '_video_poster' );
  
          ?&gt;
              &lt;div class="row"&gt;
                  &lt;div class="columns small-12 medium-7 large-8 video-single"&gt;
                      &lt;?php echo do_shortcode("[video src='" . $video[0] . "' poster='" . $poster[0] . "' width='800' height='640' preload='none' ]") ?&gt;
                      &lt;ul class="channel-share"&gt;
                          &lt;li&gt;&lt;a class="text-center" href="https://www.facebook.com/sharer/sharer.php?u=&lt;?php the_permalink(); ?&gt;" title="Share on Facebook" target="_blank"&gt;&lt;i class="fa fa-facebook"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;a class="text-center" href="https://twitter.com/home?status=&lt;?php the_title(); ?&gt;-&lt;?php the_permalink(); ?&gt;" title="Share on Twitter" target="_blank"&gt;&lt;i class="fa fa-twitter"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;a class="text-center" href="https://www.linkedin.com/shareArticle?mini=true&amp;url=&lt;?php the_permalink(); ?&gt;&amp;title=&lt;?php the_title(); ?&gt;" title="Share on Linked In" target="_blank"&gt;&lt;i class="fa fa-linkedin"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;a class="text-center" href="https://plus.google.com/share?url=&lt;?php the_permalink(); ?&gt;" title="Share on Google+" target="_blank"&gt;&lt;i class="fa fa-google-plus"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
                      &lt;/ul&gt;
                      &lt;?php the_content(); ?&gt;
                  &lt;/div&gt;
                  &lt;div class="columns small-12 medium-5 large-4 video-single"&gt;
                      &lt;aside&gt;
                          &lt;ul class="iot-channel-sidebar"&gt;
                              &lt;?php
  
                              $args = array(
                                      'post_type'      =&gt; 'test_video',
                                      'posts_per_page' =&gt; 5,
                                      'orderby'        =&gt; 'rand'
                                  );
  
                              $channel = new WP_Query( $args );
  
                              if( $channel-&gt;have_posts() ) : while( $channel-&gt;have_posts() ) : $channel-&gt;the_post();
                                  $poster = get_post_meta( get_the_ID(), '_video_poster' );
                                  $id = get_the_ID();
                                  $video_ajax_url = VIDEO_URI . '/inc/video_ajax.php';
                              ?&gt;
                              &lt;?php if( $poster ) { ?&gt;
                                  &lt;li class="video-archive-item"&gt;
                                      &lt;div class="video-poster"&gt;
                                          &lt;a title="&lt;?php the_title(); ?&gt;" id="video_&lt;?php echo $id; ?&gt;"&gt;
                                              &lt;img src="&lt;?php echo $poster[0]; ?&gt;" alt="&lt;?php the_title(); ?&gt;" /&gt;
                                          &lt;/a&gt;
                                      &lt;/div&gt;
                                      &lt;div class="video-title"&gt;
                                          &lt;a title="&lt;?php the_title(); ?&gt;"&gt;
                                              &lt;h4&gt;&lt;?php the_title(); ?&gt;&lt;/h4&gt;
                                          &lt;/a&gt;
                                      &lt;/div&gt;
                                  &lt;/li&gt;
                                  &lt;script type="text/javascript"&gt;
                                          jQuery("#video_&lt;?php echo $id; ?&gt;").click(function(){
                                              jQuery.ajax({
                                                  url: '&lt;?php echo $video_ajax_url; ?&gt;',
                                                  type: 'POST',
                                                  data: {id: '&lt;?php echo $id; ?&gt;'},
                                                      success: function(data){
                                                      $('.wp-video').html(data); // Load data into a &lt;div&gt; as HTML
  
                                                  }
                                              });
                                          });
                                  &lt;/script
                              &lt;?php } ?&gt;                  
                              &lt;?php endwhile; endif; ?&gt;
                          &lt;/ul&gt;
                      &lt;/aside&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
          &lt;?php  endwhile; endif;
  
          $output = ob_get_clean();
  
          return $output;
  
  
      }
  </code></pre>
  
  <p>My ajax:</p>
  
  <pre><code>&lt;?php
  
  global $post;
  $postID = $_POST['id'];
  
  setup_postdata( $postID ); 
  
  echo $postID;
  
  $video = get_post_meta( $postID, '_video_url' );
  $poster = get_post_meta( $postID, '_video_poster' );
  
  echo do_shortcode("[video src='" . $video[0] . "' poster='" . $poster[0] . "' width='800' height='640' preload='none' ]")
  
  
  
  ?&gt;
  </code></pre>