• Resolved George

    (@quantum_leap)


    I am using an Events Manager plugin and I list the events through WP Show Posts. The events plugin makes use of an event start date custom field named _event_start_date which I need to sort my events with.

    My plan is to convert the date to a timestamp so I can then use the following shortcode to sort through the resulting number:
    [wp_show_posts id="369" settings="meta_key=_event_start_date&orderby=meta_value_num&order=ASC"]

    I am also aware of the strtotime() PHP function but, how can I do the conversion inside a WPSP function that will only affect the event start date while I display the events with WPSP?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Elvin

    (@ejcabquina)

    Hi there,

    You can make a helper shortcode for this.

    Try my suggestion here – https://wpshowposts.com/support/topic/snippet-to-convert-a-shortcode/#post-31650

    Example:

    add_shortcode('dynamic_wpsp', function($atts){
        $atts = shortcode_atts( array(
    			'id' => ''
    		), $atts, 'dynamic_wpsp' );
    
        $settings = array(
            'order'      => 'ASC',
            'orderby'  => 'meta_value',
            'meta_key'  => 'id_number',
        );
     
        ob_start();
        wpsp_display( $atts['id'], $settings );
        return ob_get_clean();
    });

    I don’t think you need strtotime() though. Just change the field value on ACF.

    Thread Starter George

    (@quantum_leap)

    I am not using ACF:

    “I am using an Events Manager plugin”. Any chance I could include the conversion inside this function?

    Plugin Support Elvin

    (@ejcabquina)

    I am not using ACF:

    “I am using an Events Manager plugin”. Any chance I could include the conversion inside this function?

    You can still use the code but add the _event_start_date. as meta key

    Example:

    add_shortcode('dynamic_wpsp', function($atts){
        $atts = shortcode_atts( array(
    			'id' => ''
    		), $atts, 'dynamic_wpsp' );
    
        $settings = array(
            'order'      => 'ASC',
            'orderby'  => 'meta_value',
            'meta_key'  => '_event_start_date',
        );
     
        ob_start();
        wpsp_display( $atts['id'], $settings );
        return ob_get_clean();
    });
    Thread Starter George

    (@quantum_leap)

    It works perfectly, thanks!

    Plugin Support Elvin

    (@ejcabquina)

    No problem. 😀

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Sort by custom date’ is closed to new replies.