Home › Forums › Pro Support › Showing only forthcoming event in post
Tagged: future events
- This topic has 3 replies, 3 voices, and was last updated 1 year, 6 months ago by
elvin.
-
AuthorPosts
-
February 22, 2022 at 8:27 am #36655
Ema
ParticipantHello 🙂
I would like to use WPSP to show up and coming events, but not events any from the archive/past.
I have an ACF field ‘start_date’. But I also can see that WPSP has an option to show ‘Future’ posts.
What is the best method for this?Thank you in advance
EmaFebruary 22, 2022 at 9:06 pm #36662Fernando
ParticipantHi Ema,
This would depend on your website’s structure.
“Future” posts are posts “Scheduled to be published in a future date. (future)”
Reference: https://wordpress.org/support/article/post-status/
This means that when a post is published, it will no longer appear in the specific list.
This could indeed work for you if you have two lists. One for “Future” posts to show up and coming events, and another list for already “Published” posts for archive/past events.
If you wish to use ACF however, here is a helpful thread where Tom explains how to do it: https://wpshowposts.com/support/topic/custom-fields/#post-220
Hope this answers your inquiry! 🙂
-
This reply was modified 1 year, 7 months ago by
Fernando.
February 24, 2022 at 4:19 am #36673Ema
ParticipantHello Fernando, I’m still a little stuck
My ACF field is ‘start_date’ and my list id is ‘4943’.
Would the code look like this below? Also – do I still add via shortcode, and add this function via my child theme?
add_action( 'wpsp_before_content', function( $settings ) { if ( 4943 === $settings['list_id'] ) { $meta = get_post_meta( get_the_ID(), '_start_date', true ); if ( $meta ) { echo $meta; } } } );
All my CPT event posts have the ACF field of ‘start_date’ – how does this only show the current events.
Many thanks in advance
February 24, 2022 at 10:16 pm #36679elvin
ModeratorHi Ema,
All my CPT event posts have the ACF field of ‘start_date’ – how does this only show the current events.
It should be possible but we’ll have to resort to a bit of modification to the plugin’s file.
Make this change in your wp-show-posts.php file: https://github.com/tomusborne/wp-show-posts/commit/286caf1164db8b6b6f38b85d3a011b519a27f4de
We then need to do some filtering. The PHP will be something like this:
add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) { if ( 4943 === $settings['list_id'] ) { $args['meta_query'] = array( array( 'key' => 'start_date', 'orderby' => 'meta_value_num', 'order' => 'DESC', ) ); } return $args; });
The
key
params’ value is your ACF slug. Theorder
param value is there sorting order depending on what you’ve set onorderby
param. These order params can be omitted. -
This reply was modified 1 year, 7 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.