Display upcoming events with Views
- This topic has 2 replies, 2 voices, and was last updated 3 years, 1 month ago by
smt ontwerpstudio.
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
March 10, 2022 at 9:53 PM #34458
smt ontwerpstudio
ParticipantHi,
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
March 11, 2022 at 12:54 PM #34472Long Nguyen
ModeratorHi,
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 %}
March 11, 2022 at 4:21 PM #34476smt ontwerpstudio
ParticipantHi, 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 %}
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.