我正在使用事件管理插件,我想通过短代码显示一些特定的事件详细信息。
我发现了关于这个插件的短代码的非常有用的指南:
但我有一个问题。如指南中所述,您必须始终通过 id 短代码属性提供事件的 ID,如下所示:
[tribe_event_inline id="167"]
我想要实现的是短代码始终使用它所在帖子的 ID。
我尝试添加额外的短代码
add_shortcode( 'return_post_id', 'the_dramatist_return_post_id' );
function the_dramatist_return_post_id() {
return get_the_ID();
}
然后将短代码嵌套在原始代码中,但显然它不会那样工作。
知道如何实现这一目标吗?
预先感谢您的任何想法。
最佳答案
也许有帮助:
add_shortcode( 'return_post_id', 'the_dramatist_return_post_id' );
function the_dramatist_return_post_id() {
global $post;
return $post->ID ?? '';
}
关于php - 在 WordPress 短代码中使用当前帖子 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58933766/