【发布时间】:2019-01-14 15:59:39
【问题描述】:
如何在循环中将$the_slug 的内容传递给$post_name 变量?
$tags = get_the_tags();
foreach ($tags as $tag){
global $post;
$the_slug = $tag->slug; //contains 10ish words that associate with my permalinks: welcome, home, about, contact, etc
$post_id = 'welcome';
$post_name = $the_slug; //fails to populate here
$queried_post = get_post($post_name); //if changed to $post_id works but only 'welcome' post
$excerpt = $queried_post->post_excerpt;
$excerpt = apply_filters('the_content', $excerpt);
$excerpt = str_replace(']]>', ']]>', $excerpt);
echo $excerpt . "\n\n";
}
感谢您的关注。
【问题讨论】:
-
我们需要更多信息。
$tag->slug是数组还是字符串?get_post函数长什么样子? -
get_post 的第一个参数必须是 Post ID 或 post 对象。我想说,这很可能是 stackoverflow.com/questions/14979837/… 的副本
-
$tag->slug 包含字符串:welcome、home、about、contact 等...$get_posts = get_posts($tag->slug);...get_posts 是一个 wordpress 数组,包含元:[ID]、[post_content]、[post_title]、[post_excerpt]、[post_status]、[comment_status] 等...我试图让我的标签描述提取同名/slug 的帖子摘录.