• Hi – great work on the plugin!!

    I have created my own shortcode, because I required a different display for the latest event on my homepage (with featured image as background cover).

    I have been able to pull featured background image and normal post stuff like title from your custom post type – and I have created my own shortcode to put my loop on my homepage.

    All I need now is to pull the ‘Start Date’ from the event to display also – I was wondering if you could help me. I can provide you my current custom post loop code if this helps?

    Thanks,

    Lee

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Guido

    (@guido07111975)

    Hi Lee,

    Is your own shortcode part of the plugin as well, or is it outside VSEL?

    Guido

    Plugin Author Guido

    (@guido07111975)

    I can provide you my current custom post loop code if this helps?

    Yes please!

    Guido

    Thread Starter leemasondesign

    (@leemasondesign)

    Thanks Guido…..

    So (for the purpose of setting the event image as the background of a div on the homepage) I created my own shortcode.

    It is currently pulling the ‘Event Featured Image’ and the ‘Event Title’ – but I would also like to pull the ‘Event start date’ , ‘Event end Date’ – and was not able to figure out what ID’s/hooks to use for these?

    The code is:

    // CREATE A CUSTOM SHORTCODE FOR A LOOP THAT SETS POST THUMBNAIL AS IMAGE BACKGROUND FOR VSEL

    function events_loop_shortcode() {
    $args = array(
    ‘post_type’ => ‘event’,
    ‘post_status’ => ‘publish’,
    ‘posts_per_page’ => 1,// Limit to one latest post
    );

    $my_query = null;
    $my_query = new WP_query($args);

    if($my_query->have_posts()):
    while($my_query->have_posts()) : $my_query->the_post();

    $event_image_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );

    echo ‘<div class=”event-box” style=”background-image: url(‘. $event_image_url.’)”>’; //Set post thumbnail as background container image
    echo ‘<div class=”event-info”>’; //Wrapper for event info
    echo ‘<div class=”event-title”><h3>‘.get_the_title( $id ).’</h3></div>’; // The event title
    echo ‘<div class=”event-date”><h3>‘.$widget_start_date.’</h3></div>’; //The date
    echo ‘</div>’; // Close event info wrapper
    echo ‘</div>’; //Close event box

    endwhile;
    wp_reset_postdata();

    else :
    _e( ‘Sorry, no posts matched your criteria.’ );
    endif;
    }

    add_shortcode( ‘events-loop’, ‘events_loop_shortcode’ );

    ———–

    Thanks, Lee

    Plugin Author Guido

    (@guido07111975)

    Hi Lee,

    This should work:

    
    function events_loop_shortcode() {
    global $post;
    $args = array(
    'post_type' => 'event',
    'post_status' => 'publish',
    'posts_per_page' => 1,// Limit to one latest post
    );
    
    $my_query = null;
    $my_query = new WP_query($args);
    
    if($my_query->have_posts()):
    while($my_query->have_posts()) : $my_query->the_post();
    
    $event_image_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    $event_start_date = get_post_meta( $post->ID, 'event-start-date', true );
    
    echo '<div class=”event-box” style=”background-image:url('.$event_image_url.')”>'; //Set post thumbnail as background container image
    echo '<div class=”event-info”>'; //Wrapper for event info
    echo '<div class=”event-title”><h3>'.get_the_title( $post->ID ).'</h3></div>'; // The event title
    echo '<div class=”event-date”><h3>'.wp_date('j F Y', $event_start_date).'</h3></div>'; //The date
    echo '</div>'; // Close event info wrapper
    echo '</div>'; //Close event box
    
    endwhile;
    wp_reset_postdata();
    
    else :
    _e( 'Sorry, no posts matched your criteria.' );
    endif;
    }
    
    add_shortcode( 'events-loop', 'events_loop_shortcode' );
    

    You might want to change the date format j F Y.

    Guido

    Thread Starter leemasondesign

    (@leemasondesign)

    Actually – please ignore me, I’ve just realised I was pulling in the date correctly first time around using this code below ….. but it was an unrecognisable sequence of numbers, so I thought my code was wrong – but turns out the date is just showing as

    1600214400 – which appears to be pulling the time instead??

    Please view it live here: http://lmd-1.co.uk/ (where it says test event)

    Please view here the date isn’t working:

    ——

    // CREATE A CUSTOM SHORTCODE FOR A LOOP THAT SETS POST THUMBNAIL AS IMAGE BACKGROUND FOR VSEL

    function events_loop_shortcode() {
    $args = array(
    ‘post_type’ => ‘event’,
    ‘post_status’ => ‘publish’,
    ‘posts_per_page’ => 1,// Limit to one latest post
    );

    $my_query = null;
    $my_query = new WP_query($args);

    if($my_query->have_posts()):
    while($my_query->have_posts()) : $my_query->the_post();

    $event_image_url = wp_get_attachment_url ( get_post_thumbnail_id($post->ID) );
    $widget_start_date = get_post_meta( get_the_ID(), ‘event-start-date’, true );

    echo ‘<div class=”event-box” style=”background-image: url(‘. $event_image_url .’)”>’; //Set post thumbnail as background container image
    echo ‘<div class=”event-info”>’; //Wrapper for event info
    echo ‘<div class=”event-title”><h3>‘. get_the_title( $id ).’</h3></div>’; // The event title
    echo ‘<div class=”event-date”><h3>‘. $widget_start_date .’ something….</h3></div>’; //The date
    echo ‘</div>’; // Close event info wrapper
    echo ‘</div>’; //Close event box

    endwhile;
    wp_reset_postdata();

    else :
    _e( ‘Sorry, no posts matched your criteria.’ );
    endif;
    }

    add_shortcode( ‘events-loop’, ‘events_loop_shortcode’ );

    ——

    Thanks Lee

    Plugin Author Guido

    (@guido07111975)

    Hi Lee,

    But I already gave you a working example in my previous reply, so I don’t understand what is your question now?

    Guido

    p.s. when adding code in this forum, please click the “code” button before and after your code.

    Thread Starter leemasondesign

    (@leemasondesign)

    Hi Guido

    Sorry – you did indeed, I had sent over my follow up before realising you had responded, thanks kindly for your response – I will test now!

    Thanks,

    Lee

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Pull the VSEL start date into my own custom post loop for output’ is closed to new replies.