I am trying to create a post list that will show current users posts by specific category and show the post id inside the title. So, I wrote the code below, but it isn't working work. Any suggestions please:

if ( is_user_logged_in() ):
$user_id = get_current_user_id();
    'post_type' => 'post',
    'post_category' => array( 2 ),
    'posts_per_page' => 10,
    'author' => $user_id
$wp_query = new WP_Query($args);
while ( have_posts() ) : the_post(); 
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php get_the_ID(); ?></a> 

else :

    echo "not logged in";


  • What specifically doesn't work? If everything except the ID is showing, try echo get_the_ID(); instead of just get_the_ID();.
    – WebElaine
    Commented Sep 19, 2017 at 20:01
  • @WebElaine Working good but show all post not the specific category please check this Commented Sep 19, 2017 at 20:02

1 Answer 1


As far as i know there is no arguments array key name 'post_category' in WP_Query . Insted of 'post_category' use either 'category__in' => array( 2, 6 ) or category_name' => 'staff'.

And also for the id case use echo get_the_ID() ... to print the post id


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.