We're merging with GenerateBlocks! Learn more here.

[Support request] Showing only forthcoming event in post

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Showing only forthcoming event in post

Tagged: 

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #36655
    Ema
    Participant

    Hello 🙂

    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
    Ema

    #36662
    Fernando
    Participant

    Hi 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 3 months ago by Fernando.
    #36673
    Ema
    Participant

    Hello 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

    • This reply was modified 3 months ago by Ema.
    • This reply was modified 3 months ago by Ema.
    #36679
    elvin
    Moderator

    Hi 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. The order param value is there sorting order depending on what you’ve set on orderby param. These order params can be omitted.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.