Support Forum
Hi,
I use views in combination with Elementor.
I have a posttype Events with a start date, but some don't have a start date (because they are always available, as videolink)
I have created a view to show upcoming events and display it with a shortcode on the homepage. What code do I add to display only upcoming events (and the posts without date)??
Code:
{% set args = { post_type: "event", posts_per_page: 6, tax_query: [ { taxonomy: 'event-type', field: 'slug', terms: 'yoga-events-live' } ] } %}
{% set posts = mb.get_posts( args ) %}
{% for post in posts %}
<div class="event_card-row">
<div class="event_card-date">
{% if post.event_with_datum == 'No' %}
View every moment
{%else%}
{{ post.event_startdatum | date( 'd F Y' ) }}
{% endif %}
</div>
<div class="event_card-row-title-wrapper">
<h4 class="event_card-row-title">
{{ post.post_title }}
</h4>
</div>
</div
Hi,
You can create the condition to check the field value before showing the post, like this
{% set posts = mb.get_posts( args ) %}
{% for post in posts %}
<!-- create your condition before showing the post -->
{% if post.event_with_datum == 'No' %}
<div class="event_card-row">
<div class="event_card-date">
{{ post.event_startdatum | date( 'd F Y' ) }}
</div>
<div class="event_card-row-title-wrapper">
<h4 class="event_card-row-title">
{{ post.post_title }}
</h4>
</div>
</div>
{%else%}
something here
{% endif %}
{% endfor %}
Hi, thanks for your answer. I came up with the following code, but can't get it to work..
{% set posts = mb.get_posts( args ) %}
{% for post in posts %}
{% if ( post.event_startdatum | date( 'd F Y' ) > "now" | date( 'd F Y' ) ) and ( post.event_with_datum == 'Ja') %}
<div class="event_card-row">
<div class="event_card-date">
{{ post.event_startdatum | date( 'd F Y' ) }}
</div>
<div class="event_card-row-title-wrapper">
<h4 class="event_card-row-title">
{{ post.post_title }}
</h4>
</div>
</div>
{%else%}
<div class="event_card-row">
<div class="event_card-date">
Op elk moment
</div>
<div class="event_card-row-title-wrapper">
<h4 class="event_card-row-title">
{{ post.post_title }}
</h4>
</div>
</div>
{% endif %}
{% endfor %}