title: Get all published posts in Wordpress, performance issues due to long result set
body: <p>I need to build a array like this:</p>
  
  <pre><code>$arrPosts = array(
      thePostID =&gt; "The Post Title"
  )
  </code></pre>
  
  <p>I'm doing as follow:</p>
  
  <pre><code>$posts = get_posts(
      array(
          'numberposts' =&gt; -1,
          'post_status' =&gt; 'published',
          //'post_type' =&gt; get_post_types('post', 'opinion')
      )
  );
  
  foreach($posts as $post) {
      $article[] = [
          $post-&gt;ID =&gt; $post-&gt;title
      ];
  }
  </code></pre>
  
  <p>But it takes a long time to process which is not suitable (I had to set <code>define('WP_MAX_MEMORY_LIMIT','1024M')</code> which is a lot of memory). I need to get only posts from that are post and opinion custom post type.</p>
  
  <p>Does any knows a better way to achieve this?</p>