【发布时间】:2017-10-02 09:38:59
【问题描述】:
问题:如何使用 get_post_meta() 访问另一个帖子的帖子 ID?
你好,我目前在一个 Wordpress 网站上工作,在这个网站上我想从另一个帖子中访问 post-id,我打算使用 get_post_meta() 数组,但我不知道如何使用它。我不确定在哪里可以找到 $key 以及如何使用它?
这是我目前的代码...
帖子 1(我想“回显”帖子 ID 的帖子)。
<?php
$educator_meta= get_post_meta(get_the_id(), 'educator_id');
?>
<html>
<div class="container">
<?php
echo "This is the post-id of the educator post: ", $educator_meta[0];
echo "This is the current posts post-id: ", get_the_ID();
?>
</div>
</html>
Post 2(我想从中获取 post-id 的页面)。
<?php
$current_educator_id = get_the_id();
$course_lessons = new WP_Query( array(
'post_type' => 'educator',
'order' => 'asc',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'educator_id',
'value' => $current_educator_id,
'compare' => 'IN',
),
),
) );?>
【问题讨论】: