WordPress.org

Ready to get started?Download WordPress

Forums

Display different category based on logged in user (2 posts)

  1. steweir
    Member
    Posted 1 year ago #

    I have set up categories with the same names as my users so each user has its on category with identical names.

    I want to only show that category when the user is logged in, this is the code iv written its my fist attempt at something like this though and im stuck :(

    <?php

    global $current_user;
    $user = get_current_user($user->user_login);
    $username = $user['username'];

    ?>

    <?php get_header(); ?>

    <div id="content">
    <?php
    query_posts("cat=$username");
    while (have_posts()) : the_post();
    the_content();
    endwhile;
    ?>
    </div>

  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

    you would possibly need to use the WordPress function http://codex.wordpress.org/get_currentuserinfo

    and use the category slug in the query:

    http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

Topic Closed

This topic has been closed to new replies.

About this Topic