I have a website with a taxonomy called “db_themen” with different values. The posts from from my webiste are assigned to these taxonomy values from “db_themen”.
On my website, a user can choose in his frontend user profile which “db_themen” he is interested in and save this input. This works through an ACF field of the type “Taxonomy” (field name: “meine_themen”), which is linked to the taxonomy “db_themen”.
According to his input, only posts that are assigned to the same taxonomies are supposed to show on the frontend archives (Elementor archives Loop Grid) for this user.
I tried to code something within my functions.php, but I am a total beginner. The only thing this code does is hide all posts entries in the backend:
function abfrage_meine_themen($query) {
    if ($query->is_main_query() && is_user_logged_in()) {
    $ausgewaehlte_themen = get_field('meine_themen', 'user_' . get_current_user_id());
        if ($ausgewaehlte_themen) {         
            $tax_query = array(
                array(
                    'taxonomy' => 'db_themen',
                    'field'    => 'slug',
                    'terms'    => $ausgewaehlte_themen,
                ),
            );
            $query->set('tax_query', $tax_query);
        }
    }
}
add_action('pre_get_posts', 'abfrage_meine_themen');
Can someone please tell me where my mistakes are? I am sure there are several
