This is fixed thanks to Alex’s answer below.
So this is a bit of a weird one. I am setting up so I have category’s with names “cat1, cat2, cat3” etc.
And say I had users called “cat1, cat2, cat3” so they matched the same as the category names.
I am then wanting to somehow only show the posts to the user that relates to their category, so basically if USER: “cat1” is logged in then they could only see the posts in category “cat1” as it matches their username.
I know you can do this to show posts only that the current user logged in has made but this wont work as the way the posts get put into the category complicated to explain.
<?php
// The Query
$args = array(
'post_status'=> '.....'
);
global $user_ID;
get_currentuserinfo();
if($user_ID) {
query_posts( $args,"author=$user_ID" );
}
?>
So if anyone has any insight into only showing posts to a user that matches a category with the same name as the user logged in hopefully they will be kind enough to help out.
It seems like you’ve started a round-about way of getting this accomplished. Since you have categories already set up with the username, you should just be able to place that in your query
EDIT:
did you do
var_dump($current_user->ID)to see if it matches the category name? That variable from the object might only contain an ID (like “1” or “178” etc). If that was the case, you’d need something likeThen just replace the array with
Alternatively, look at the Current User Functions (here). You may be able to use
instead. You could also just try
var_dump($current_user)(after callingglobal $current_user; get_currentuserinfo();) and see what variable contains the string you need