Category selectable homepage

It’s important to add guard clauses to prevent modification of other queries. (For example, menus). We are trying to modify the main query here, so we should bail if this is not the main query.

function my_get_posts( $query ) {

    // Bail if this is not the main query.
    if ( ! $query->is_main_query() ) {
        return;
    }

    // Other guard clauses to ensure we don't affect queries unintentionally.
    // Sounds like you are just trying to target the homepage, so we could check for that too.
    if ( ! is_home() ) {
        return;
    }
    
    // We only need to modify the query for logged in users.
    if ( ! is_user_logged_in() ) {
        return;
    }
    
    // Modify the query as needed...

}
add_action( 'pre_get_posts', 'my_get_posts' ); // Note that pre_get_posts is an action, not a filter.