dongyun3805 2014-12-07 21:46 采纳率: 0%
浏览 36

该帖子的永久链接不起作用

I have a page which retrieves blogposts from several blogs under the same tag or category. I have problems with retrieving the permalink for the blogpost, it redirects to the same blog all the time and says that the page doesn't exist, i.e. it always goes to blog #5 stated in the 5th line and ignores the switch statement Here is my code:

<?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(); 
        }
        ?>
  • 写回答

1条回答 默认 最新

  • duanlou7910 2014-12-07 22:42
    关注

    Is that because of you put

     switch_to_blog(5);
    

    in the 5th line, and the page redirects you to that blog BEFORE the switch statement is even read?

    Just asking, I don't really understand your code, but I hope you find this helpful!

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用