Roots Discourse

I need help with Post per limit option in Sage

Hello .I have problem with posts_per_page option, i cant show how many post i want in my custom template, its just show all the post. Here is my code

$args = [
  'post_type'      => 'post',
  'post_status'    => 'publish',
  'posts_per_page' => '2',

$the_query = new WP_Query( $args );

@if ( $the_query->have_posts() )

  @while ( $the_query->have_posts() ) @php $the_query->the_post() @endphp
  @php $featured_image = get_the_post_thumbnail(get_the_id(), 'medium') @endphp

    <div class="img-post">
          {!! $featured_image !!}
    <h3>{{ get_the_title() }} </h3>
  @endwhile<!-- end of the loop -->

@php wp_reset_postdata() @endphp

Posts_per_page accepts numbers, not strings. It should be 2 not ‘2’. For something as small as 2, it might be better to use get_posts() instead of a custom query. It should be faster but require a bit more to parse the result

Also, remove () from the end:

@endif not @endif()