I have a custom post type named event
. At the moment it has about 20 posts.
On the main events page the included MB view below displays all of the posts, chronologically ordered by the start date of the events.
I would like to show only the first 3 event posts on the homepage, but limiting the posts_per_page
to 3
shows no results. If I increase that value to 10, for example, I do get posts to display, but they aren't the next upcoming events.
Is it possible to only display the next (chronologically speaking) 3 upcoming events?
{% set args = { post_type: "event", posts_per_page: 3 } %}
{% set posts = mb.get_posts( args ) %}
{% for key, post in posts|sort((a, b) => a.bdr_event_start_date <=> b.bdr_event_start_date) %}
{% if post.bdr_event_start_date >= "now"|date("Y-m-d") or post.bdr_event_end_date >= "now"|date("Y-m-d") %}
<div class="bxb-event-grid-item">
<div>
<img src="{{ post.thumbnail.large.url }}" alt="{{ post.thumbnail.large.alt }}" width="{{ post.thumbnail.large.width }}" height="{{ post.thumbnail.large.height }}">
<a href="{{ post.url }}"><h2>{{ post.post_title}}</h2></a>
<div class="bxb-event-date-range">
{% if post.bdr_event_start_date == post.bdr_event_end_date %}
{{ post.bdr_event_start_date | date( 'F jS, Y' ) }}
{% endif %}
{% if post.bdr_event_start_date != post.bdr_event_end_date %}
{{ post.bdr_event_start_date | date( 'F jS' ) }}—{{ post.bdr_event_end_date | date( 'F jS, Y' ) }}
{% endif %}
</div>
</div>
</div>
{% endif %}
{% endfor %}
Thank you for any assistance you can provide!