• Hi–I have been battling over the following script for a few days. My users are bound to categories (using wp_named_users plugin, which gives me a wp_named_users table in the Mysql database).
    I have tried using the code below to select and display the posts of the specific categories relevant to the currently loggied inuser, which would display on his or her own ‘home page’. i have got the user home page set up, but cannot get this script to return values. Inner Join is posts.ID and named_users.post.id.

    Please can I have any suggestions for why this script may not be returning a positive result–it goes into the “else” option all the time.

    Thanks very much!!

    <?php
    $querystr = “
    SELECT wpposts.*
    FROM $wpdb->posts wpposts, $wpdb->named_users wp_named_users
    WHERE wpposts.ID = wp_named_users.post_id
    AND wp_named_users.user_id = ‘$current_user->ID’
    AND wpposts.post_type = ‘post’
    AND wpposts.post_status = ‘publish’
    AND wpposts.post_date < NOW()
    ORDER BY wpposts.post_date DESC
    “;

    $pageposts = $wpdb->get_results($querystr);

    ?>
    <?php if ($pageposts): ?>
    <?php foreach ($pageposts as $post): ?>
    <?php setup_postdata($post); ?>

    <div class=”post” id=”post-<?php the_ID(); ?>”>
    <h2>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”>
    <?php the_title(); ?>
    </h2>
    <small><?php the_time(‘F jS, Y’) ?> <!– by <?php the_author() ?> –></small>
    <div class=”entry”>
    <?php the_content(‘Read the rest of this entry »’); ?>
    </div>

    <p class=”postmetadata”>Posted in <?php the_category(‘, ‘) ?> | <?php edit_post_link(‘Edit’, ”, ‘ | ‘); ?>
    <?php comments_popup_link(‘No Comments »’, ‘1 Comment »’, ‘% Comments »’); ?></p>
    </div>
    <?php endforeach; ?>

    <?php else : ?>
    <h2 class=”center”>Not Found</h2>
    <p class=”center”>Sorry, but you are looking for something that isn’t here.</p>
    <?php include (TEMPLATEPATH . “/searchform.php”); ?>
    <?php endif; ?>

    </div>

  • The topic ‘Dispalying Posts in Specific Categories Tied to Current USer’ is closed to new replies.