Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1088572

    Hi,

    I have blog category set up to display upcoming events. My problem is the publish date of the article is being shown appose to the date of the event.

    Is there a way to force the posts (event) to publish and set the published date to the date of the event?

    Thanks

    #1089092
    Jade
    Moderator

    Hi there,

    Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:

    – Link to your site
    – WordPress Admin username / password
    – FTP credentials

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    #1091435
    This reply has been marked as private.
    #1091457
    Rad
    Moderator

    Hi there,

    Dates are always changeable, it’s an available option along with the publish/update button ( Published on: ) while editing your post. You can set it to any date you want.

    BUT, remember that WordPress will only display posts from oldest up to the current date. Which means, posts with the future date is hidden until the time comes. Event and Publish date are different, so you shouldn’t do that. Changeable publish date’s main purpose is to schedule posts and not for events.

    How are you gonna display an event if it’s scheduled to appear in the future?

    Thanks!

    #1091619
    This reply has been marked as private.
    #1091745
    Christian
    Moderator

    Hey there,

    Please follow the steps below:

    1. Create an Advanced Custom Field and label it Event Date. The generated name will be event_date. Alternatively, you can copy the code below and save it as a .json file so you can import in ACF tools. See https://community.theme.co/kb/integrated-plugins-acf-pro/ for ACF Pro usage instructions.

    [
        {
            "key": "group_578cb6b7c13f1",
            "title": "Event",
            "fields": [
                {
                    "key": "field_578cb6c8f6865",
                    "label": "Event Date",
                    "name": "event_date",
                    "type": "date_picker",
                    "instructions": "",
                    "required": 0,
                    "conditional_logic": 0,
                    "wrapper": {
                        "width": "",
                        "class": "",
                        "id": ""
                    },
                    "display_format": "F j, Y",
                    "return_format": "d\/m\/Y",
                    "first_day": 1
                }
            ],
            "location": [
                [
                    {
                        "param": "post_type",
                        "operator": "==",
                        "value": "post"
                    }
                ]
            ],
            "menu_order": 0,
            "position": "normal",
            "style": "default",
            "label_placement": "top",
            "instruction_placement": "label",
            "hide_on_screen": "",
            "active": 1,
            "description": ""
        }
    ]

    2. Add the code below in your functions.php

    function x_shortcode_recent_posts_custom( $atts ) {
      extract( shortcode_atts( array(
        'id'           => '',
        'class'        => '',
        'style'        => '',
        'type'         => 'post',
        'count'        => '',
        'category'     => '',
        'offset'       => '',
        'orientation'  => '',
        // 'show_excerpt' => 'true',
        'no_sticky'    => '',
        'no_image'     => '',
        'fade'         => ''
      ), $atts, 'x_recent_posts' ) );
    
      $allowed_post_types = apply_filters( 'cs_recent_posts_post_types', array( 'post' => 'post' ) );
      $type = ( isset( $allowed_post_types[$type] ) ) ? $allowed_post_types[$type] : 'post';
    
      $id            = ( $id           != ''     ) ? 'id="' . esc_attr( $id ) . '"' : '';
      $class         = ( $class        != ''     ) ? 'x-recent-posts cf ' . esc_attr( $class ) : 'x-recent-posts cf';
      $style         = ( $style        != ''     ) ? 'style="' . $style . '"' : '';
      $count         = ( $count        != ''     ) ? $count : 3;
      $category      = ( $category     != ''     ) ? $category : '';
      $category_type = ( $type         == 'post' ) ? 'category_name' : 'portfolio-category';
      $offset        = ( $offset       != ''     ) ? $offset : 0;
      $orientation   = ( $orientation  != ''     ) ? ' ' . $orientation : ' horizontal';
      // $show_excerpt  = ( $show_excerpt == 'true' );
      $no_sticky     = ( $no_sticky    == 'true' );
      $no_image      = ( $no_image     == 'true' ) ? $no_image : '';
      $fade          = ( $fade         == 'true' ) ? $fade : 'false';
    
      $js_params = array(
        'fade' => ( $fade == 'true' )
      );
    
      $data = cs_generate_data_attributes( 'recent_posts', $js_params );
    
      $output = "<div {$id} class=\"{$class}{$orientation}\" {$style} {$data} data-fade=\"{$fade}\" >";
    
        $q = new WP_Query( array(
          'orderby'             => 'date',
          'post_type'           => "{$type}",
          'posts_per_page'      => "{$count}",
          'offset'              => "{$offset}",
          "{$category_type}"    => "{$category}",
          'ignore_sticky_posts' => $no_sticky
        ) );
    
        if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();
    
          if ( $no_image == 'true' ) {
            $image_output       = '';
            $image_output_class = 'no-image';
          } else {
            $image              = wp_get_attachment_image_src( get_post_thumbnail_id(), 'entry-cropped' );
            $bg_image           = ( $image[0] != '' ) ? ' style="background-image: url(' . $image[0] . ');"' : '';
            $image_output       = '<div class="x-recent-posts-img"' . $bg_image . '></div>';
            $image_output_class = 'with-image';
          }
    
          // $excerpt = ( $show_excerpt ) ? '<div class="x-recent-posts-excerpt"><p>' . preg_replace('/<a.*?more-link.*?<\/a>/', '', cs_get_raw_excerpt() ) . '</p></div>' : '';
    
          $output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( __( 'Permalink to: "%s"', 'cornerstone' ), the_title_attribute( 'echo=0' ) ) ) . '">'
                     . '<article id="post-' . get_the_ID() . '" class="' . implode( ' ', get_post_class() ) . '">'
                       . '<div class="entry-wrap">'
                         . $image_output
                         . '<div class="x-recent-posts-content">'
                           . '<h3 class="h-recent-posts">' . get_the_title() . '</h3>'
                           . '<span class="x-recent-posts-date">' . do_shortcode('[acf field="event_date"]') . '</span>'
                           // . $excerpt
                         . '</div>'
                       . '</div>'
                     . '</article>'
                   . '</a>';
    
        endwhile; endif; wp_reset_postdata();
    
      $output .= '</div>';
    
      return $output;
    }
    
    add_shortcode( 'x_recent_posts_custom', 'x_shortcode_recent_posts_custom' );

    The code is essentially the same as the Recent Post shortcode except the date gets the value of the ACF field.

    See attachments to see screenshots of the setup and result.

    Hope that helps. 🙂

    #1093094

    Awesome! Thanks for your help Christian

    #1093111
    Friech
    Moderator

    Certainly, we’re happy to assist you with this.

    Cheers!

  • <script> jQuery(function($){ $("#no-reply-1088572 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>