gpt4 book ai didi

php - 该帖子的固定链接不起作用

转载 作者:行者123 更新时间:2023-11-29 23:20:31 25 4
gpt4 key购买 nike

我有一个页面,可以从同一标签或类别下的多个博客中检索博客文章。我在检索博客文章的永久链接时遇到问题,它始终重定向到同一个博客,并说该页面不存在,即它总是转到第 5 行中所述的博客 #5 并忽略 switch 语句,这里是我的代码:

<?php 
global $wpdb;
global $post;
$tag = $_GET['avain'];
$postarr = array();
switch_to_blog( 5 );
$blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} WHERE blog_id != {$wpdb->blogid} AND site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0'", ARRAY_A);
array_unshift($blogs, 1);
foreach($blogs as $blog) {
$wpdb->set_blog_id($blog[ 'blog_id' ]);
$tax_id = $wpdb->get_var("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE (taxonomy = 'post_tag' OR taxonomy = 'category') AND term_id IN (SELECT term_id FROM $wpdb->terms WHERE name='$tag')");
$post_id = $wpdb->get_results("SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = $tax_id");
foreach ($post_id as $id) {
$postarr[] = $id->object_id;
}

$postsAsCommaSepString = implode( ',', $postarr );

$posts = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}posts WHERE ID IN ($postsAsCommaSepString)");
foreach ($posts as $post):setup_postdata($post);
$author = get_the_author();
switch ($author) {
case "Kate":
switch_to_blog(3);
break;
case "Maria":
switch_to_blog(4);
break;
case "Germanica":
switch_to_blog(5);
break;

}
?>

<div class="post"><header class="post-header"><div class="date-holder"><span><?php the_time('j F, Y') ?></span></div>
<a href="<?php echo get_permalink($post->ID); ?>"><?php the_title(); ?></a></header>
<div class="post-content"><?php the_content(); ?></div></div>
<?php endforeach;
wp_reset_postdata();
}
?>

最佳答案

是不是因为你放了

 switch_to_blog(5);

在第 5 行,页面会在阅读 switch 语句之前将您重定向到该博客?

只是问一下,我不太明白你的代码,但我希望你觉得这有帮助!

关于php - 该帖子的固定链接不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27348218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com