0
votes

I'm trying to display a custom loop with a dynamic category filter.

As a setup I have categories of all usernames which are created once a user creates an account.

So I am trying to echo the user's username as a category filter. It works when I echo is elsewhere on the page, but it doesn't work when I try to embed it like so:

<?php query_posts('category_name=global $current_user; if ( isset($current_user) ) {echo $current_user->user_login;} &posts_per_page=10'); ?> &posts_per_page=6'); ?>

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>  
<?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?>

<?php endwhile; else: ?>

NO Posts Present 

<?php endif; ?>

Any help would be greatly appreciated, thanks.

1
you have php tags inside php code..? Start there.Emery King
@MarshallHouse I've updated the code above with your suggestion but am coming to the same conclusion. It doesn't seem to filter.user1823055
no. you're not doing it right. You have syntax errors^. a lot of them. Besides that query_posts isn't meant for side loops, you should use WP_Query - codex.wordpress.org/Class_Reference/WP_Query - perhaps this is over your head.Emery King

1 Answers

1
votes

Without addressing whether or not you should be using query_posts, you can try refactoring your query.

<?php
  global $current_user;
  $cat = (isset($current_user)) ? "category_name=$current_user->user_login&" : "";
  query_posts($cat . 'posts_per_page=6'); 
?>

You may want to read this documentation regarding query_posts, as well.