在循环中使用的短代码中获取post id

时间:2017-05-31 23:35:59

标签: wordpress shortcode visual-composer

我觉得我在这里遗漏了一些东西。所以我使用视觉作曲家砌体网格来展示帖子。我正在尝试创建一个短代码,用于显示日期时间戳的Visual composer网格构建器,但即使在循环中使用短代码,我也无法在短代码中获得post id或类似the_title或the_date的内容。我甚至可以使用其中的其他短代码来提取标题和其他元信息,并显示帖子特定信息。

这是我的尝试......它没有输出,至少没有错误,但没有结果......

 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' );

1 个答案:

答案 0 :(得分:0)

执行var_dump($ post)并检查它是否实际上是post对象。如果循环设置为仅返回id,那么$ post变量将是ID本身。