title: Get the posts count in JS (Wordpress)
body: <p>I have site on WP. </p>
  
  <p>I'm using AJAX to show my posts. On click on 'more' button appears two more posts. And I'm trying to hide the button when all of the posts are shown. But something go wrong.</p>
  
  <p>I don't understand how to take posts count to JS (it's another variant), because construction <code>var posts_count = "&lt;?php echo $posts_count; ?&gt;</code> doesn't work - it gives only string!</p>
  
  <p><strong>JS</strong></p>
  
  <pre><code>$(function () {
  
    var posts = 2; //posts shown
    var posts_offset = 2;
  
  
  
    $("#load-post").click(function (e) {
      e.preventDefault();
  
  
      $.ajax({
        type: "GET",
        url: "/wp-admin/admin-ajax.php",
        data: ({
          action: 'loadMore',
          posts_offset: posts_offset
        }),
        success: function (data) {
          $('.news #content').append(data);
          posts_offset += 2;
  
        }
      });
  
  
    });
  
  
  });
  </code></pre>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>function loadMore() {
  
  
  
      $posts_count = wp_count_posts()-&gt;publish; 
  
      $posts_offset = $_GET['posts_offset'];
  
  
      // get your $_GET variables sorted out
  
      // setup your query to get what you want
      query_posts( array( 'posts_per_page' =&gt; 2, 'offset'=&gt; $posts_offset ) );
  
      // initialsise your output
      $output = '';
  
      // the Loop
      while (have_posts()) : the_post();
  
           ?&gt;&lt;div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 news-item"&gt;
                &lt;div class="news-date"&gt;
                  &lt;?php the_time($format = "j F Y") ?&gt;
                &lt;/div&gt;
                &lt;div&gt;
                  &lt;h3&gt;&lt;?php the_title() ?&gt;&lt;/h3&gt;
                  &lt;p&gt;&lt;?php the_content() ?&gt;&lt;/p&gt;
                &lt;/div&gt;
              &lt;/div&gt;&lt;?php
  
      endwhile;
  
    if ($posts_count - ($posts_offset + 2) &lt;= 0) { ?&gt;
        &lt;script&gt;$("#load-more").hide();&lt;/script&gt;
      &lt;?php }
  
  
      // Reset Query
      wp_reset_query();
  
      die($output);
  
  }
  </code></pre>
  
  <p>This code works, but doesn't work the part of hiding the button</p>