Skip to main content
added 16 characters in body
Source Link
Howdy_McGee
  • 20.8k
  • 24
  • 91
  • 175

I haven't tested this, but in my head it works perfectly! What we do is put add a pre_get_posts filter in our functions file then get the current user. IF user isn'tisn't registered, drop out. IF the number of user posts isn'tisn't greater than 0, drop out. IF we're notnot on the post type archive, drop out. IF all 3 conditions are trueare true, we'll replace our default blog articles with the users.

function user_posts_filter($query){
    $userID = get_current_user_id();
    
    if($userID != 0 && count_user_posts($userID) > 0 && is_post_type_archive('blog')){
        $query->set('post_type', 'articles');
        $query->set('author', $userID);
    }
}
add_action('pre_get_posts', 'user_posts_filter');

Hopefully it works for you!

I haven't tested this, but in my head it works perfectly! What we do is put add a pre_get_posts filter in our functions file then get the current user. IF user isn't registered, drop out. IF the number of user posts isn't greater than 0, drop out. IF we're not on the post type archive, drop out. IF all 3 conditions are true, we'll replace our default blog articles with the users.

function user_posts_filter($query){
    $userID = get_current_user_id();
    
    if($userID != 0 && count_user_posts($userID) > 0 && is_post_type_archive('blog')){
        $query->set('post_type', 'articles');
        $query->set('author', $userID);
    }
}
add_action('pre_get_posts', 'user_posts_filter');

Hopefully it works for you!

I haven't tested this, but in my head it works perfectly! What we do is put add a pre_get_posts filter in our functions file then get the current user. IF user isn't registered, drop out. IF the number of user posts isn't greater than 0, drop out. IF we're not on the post type archive, drop out. IF all 3 conditions are true, we'll replace our default blog articles with the users.

function user_posts_filter($query){
    $userID = get_current_user_id();
    
    if($userID != 0 && count_user_posts($userID) > 0 && is_post_type_archive('blog')){
        $query->set('post_type', 'articles');
        $query->set('author', $userID);
    }
}
add_action('pre_get_posts', 'user_posts_filter');

Hopefully it works for you!

Source Link
Howdy_McGee
  • 20.8k
  • 24
  • 91
  • 175

I haven't tested this, but in my head it works perfectly! What we do is put add a pre_get_posts filter in our functions file then get the current user. IF user isn't registered, drop out. IF the number of user posts isn't greater than 0, drop out. IF we're not on the post type archive, drop out. IF all 3 conditions are true, we'll replace our default blog articles with the users.

function user_posts_filter($query){
    $userID = get_current_user_id();
    
    if($userID != 0 && count_user_posts($userID) > 0 && is_post_type_archive('blog')){
        $query->set('post_type', 'articles');
        $query->set('author', $userID);
    }
}
add_action('pre_get_posts', 'user_posts_filter');

Hopefully it works for you!