0

I feel like I'm missing something here. So I'm using visual composer masonry grid to show posts. I'm trying to create a shortcode to use in the Visual composer grid builder that shows the date timestamp but even though the shortcode is being used in a loop I can't get the post id or things like the_title or the_date in the shortcode. I can even use other shortcodes within this one to pull in the title and other meta info and it shows post specific info.

This is my attempt... it outputs nothing, no errors at least, but no result...

 function lmi_features_time_ago_shortcode( $atts, $post ) {

    global $post;

    $output = '';

    $timestamp = get_the_date('Y-m-d g:i:s', $post->id);
    // $timestamp = time_elapsed_string($timestamp);

    $output .= $timestamp;

    return $output;

}
add_shortcode( 'social_feed_ago', 'lmi_features_time_ago_shortcode' );
Prafulla Kumar Sahu
  • 9,321
  • 11
  • 68
  • 105
Tiffany Israel
  • 460
  • 1
  • 7
  • 22
  • Are you passing $atts and $post as shortcode parameters ? – Prafulla Kumar Sahu Jun 01 '17 at 00:21
  • Sorry I'm not the best with php. I think I'm passing them by putting them in the parenthesis in the function name. I had $atts commented out, and delete them for this post, because I wasn't really using them. I uncommented them and nothing changed. – Tiffany Israel Jun 01 '17 at 14:50
  • by putting them in parenthesis in function you are defining the function and that is creating just a signature and that made the arguments needed while calling .. – Prafulla Kumar Sahu Jun 01 '17 at 16:54

1 Answers1

0

Do a var_dump($post) and check if it's actually the post object. If the loop is set to return ids only then the $post variable will be the ID itself.

Thien Hoang
  • 331
  • 2
  • 4
  • I did a var dump and a print_r and got nothing, and tried using $post instead of $post->id and none of that worked. Even though the shortcode is being used within a loop it's just not getting the post info. – Tiffany Israel Jun 01 '17 at 14:52