WordPress.org

Ready to get started?Download WordPress

Forums

Post ID = Logged in user ID (2 posts)

  1. Chibueze Okechukwu
    Member
    Posted 1 year ago #

    Is there a way to automatically insert the current user ID as the post category name or maybe have WordPress display only the post with a category name that matches the current logged user ID?

    <?php
    
        $query = new WP_Query('category_name=current-user-id');
    
        if($query->have_posts()) : while($query->have_posts()) : $query->the_post();
    
        ?> 
    
         <?php
    
           the_content( __('Read the rest of this page »', 'template'));
    
          endwhile; endif;
    
         wp_reset_postdata();
    
    ?>
  2. bythegram
    Member
    Posted 1 year ago #

    untested:

    <?php
    $current_user = wp_get_current_user();
    if ( 0 == $current_user->ID ) {
        // Not logged in.
    } else {
        $query = new WP_Query('category_name='.$current_user->ID);
        if($query->have_posts()) :
        while($query->have_posts()) : $query->the_post();
    
        the_content( __('Read the rest of this page »', 'template'));
        endwhile; endif;
        wp_reset_postdata();
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic