Quantcast
Channel: Topic Tag: MySQL | WordPress.org
Viewing all articles
Browse latest Browse all 5527

eltweety on "Show posts from different blogs under same category"

$
0
0

Hello,
I am new to wordpress and to PHP. I have a theme that I need to correct. My website has 6 blogs and i would like to display 5 categories on the main page of the blog portal and if a user clicks any of those-it would redirect to a page where there are all posts from all 6 blogs which were put under this particular category.
I have a part of the code in the functions.php, responsible for that:

function tag_posts() {
    global $wpdb;
    $tag = $_GET['avain'];
    $taxarr = array();
    $postarr = array();
    $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 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;
        }

        $posts = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}posts WHERE ID IN ($postarr)");
        global $post;
        foreach ($posts as $post):setup_postdata($post);

            '<div class="post"><header class="post-header"><div class="date-holder"><span>'.the_time('F jS, Y').'</span></div>';
            '<a href="'.$post->guid.'">'.$post->post_title.'</a></header>';
            '<div class="post-content">'.the_content().'</div></div>';
        endforeach;
    }
}

I would be happy if you could help me!


Viewing all articles
Browse latest Browse all 5527

Trending Articles