title: Get all posts from Wordpress as JSON
body: <p>I am trying ti get all the posts form my Wordpress website with the post_type "product".</p>
  
  <p>I tried the below but it doesn't work.</p>
  
  <pre><code>&lt;?php
  $args = array( 'post_type' =&gt; 'product', 'post_status' =&gt; 'publish');
  
  $loop = new WP_Query( $args );
  
  $array = array();
  
  while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post();
  
      global $product;
      $array[] = array(
          'id' =&gt; get_the_ID(),
          'title' =&gt; get_the_title()
      );
  
  endwhile;
  
  wp_reset_query();
  ob_clean();
  echo json_encode($array);
  exit();
  ?&gt;
  </code></pre>
  
  <p>Although when I add <code>'posts_per_page' =&gt; 450</code> to <code>$args</code>, it returns posts of the type, however if I add a value higher than 450 such as 500, it returns nothing again.</p>
  
  <p>I am using this to loop through all product posts and add the name, price etc. to an array in the loop.</p>
  
  <p>How do I fix the <code>$args</code> to get all the product posts.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I also recently tried:</p>
  
  <pre><code>&lt;?php
      $args="SELECT * FROM wp_posts WHERE wp_posts.`post_type` = 'product' AND wp_posts.`post_status` = 'publish'";
  
      $loop = get_results( $args );
  
      $array = array();
  
      while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post();
  
          global $product;
          $array[] = array(
              'id' =&gt; get_the_ID(),
              'title' =&gt; get_the_title()
          );
  
      endwhile;
  
     // wp_reset_query();
      ob_clean();
      echo json_encode($array);
      exit();
      ?&gt;
  </code></pre>