title: Exclude posts in Wordpress Query with an external array in post__not_in
body: <p>I am trying to pass an array via AJAX to an external php file. It's a hard-coded list of post IDs to be excluded from the query.</p>
  
  <p>This is where I'm setting the post IDs in an array, these IDs exist in the database. Then I'm passing the variable <code>$postsNotIn</code> as an imploded array to the JS file to be passed over to <code>ajax.php</code></p>
  
  <p>The problem is, it is not working. I don't think the <code>$postNotIn</code> is being passed through as an array because <code>post__not_in</code> is expecting an array.</p>
  
  <p>I tried passing <code>$features</code> instead but that didn't work either.</p>
  
  <p>I keep getting <code>0</code> as a response.</p>
  
  <p>However when I hardcode the array in the query <code>'post__not_in' =&gt; array(230, 280, 268);</code> it works fine.</p>
  
  <p>How can I pass the IDs in the correct array form to <code>ajax.php</code>?</p>
  
  <p><strong>EDIT</strong> if I wrap <code>$exclude</code> in <code>array()</code> like so <code>'post__not_in' =&gt; array($exclude)</code> it only excludes the first post ID while ignoring the remaining 2.</p>
  
  <p>the HTML button</p>
  
  <pre><code>$features = array(320, 280, 268); // Array of posts to exclude
  $postsNotIn = implode(", ", $features);
  
  &lt;a class="btn btn-lg btn-default load-more-button" 
      data-exclude="&lt;?php echo $postsNotIn; ?&gt;" 
      data-page="1" 
      data-url="&lt;?php echo admin_url('admin-ajax.php'); ?&gt;"&gt;
      Load More
  &lt;/a&gt;
  </code></pre>
  
  <p>The Javascript</p>
  
  <pre><code>$('.load-more-button:not(.loading)').on('click', function() {
      var that = $(this);
      var ajaxurl = that.data('url');
      var page = that.data('page');
      var exclude = that.data('exclude');
  
      $.ajax({
              url: ajaxurl,
              type: 'post',
              data: {
                  page: page,
                  exclude: exclude,
                  action: 'load_more'
              },
              error: function(response) {
                  console.log(response);
              },
              success: function(response) {
                  console.log(response);
              }
  </code></pre>
  
  <p>This is the external <code>ajax.php</code> file</p>
  
  <pre><code>function load_more() {
      $paged = $_POST['page'] + 1;
      $exclude = $_POST['exclude'];
  
      $query = new WP_Query(array(
          'post_type' =&gt; 'post',
          'post_status' =&gt; 'publish',
          'paged' =&gt; $paged,
          'post__not_in' =&gt; $exclude
      ));
  
  if($query-&gt;have_posts()) :
      while($query-&gt;have_posts()) : $query-&gt;the_post();
          get_template_part( 'content', get_post_format() );
      endwhile;
  else :
      echo 0;
  endif;
  
  wp_reset_postdata();
  
  die();
  </code></pre>