如何在循环中将$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";
}
感谢您的光临。
答案 0 :(得分:0)
您可以使用foreach循环遍历数组:
foreach($the_slug as $slug){
$post_name = $slug;
$queried_post = get_post($post_name); $excerpt = $queried_post->post_excerpt;
$excerpt = apply_filters('the_content', $excerpt);
$excerpt = str_replace(']]>', ']]>', $excerpt);
echo $excerpt . "\n\n";
}