• I would like to display a list of pages in a query loop, showing only the pages for which the logged in user has rights.

    At this time, all pages are shown and a message will only appear when you click on a page that does not belong to your rights group.

    Do you know if there is anything that can be done about this?

Viewing 1 replies (of 1 total)
  • Hello @woltersthijs ,

    First of all I recommend you to check this https://developer.www.ads-software.com/reference/functions/is_user_logged_in/

    Then you can modify it just like the following example –

    <?php
    if (is_user_logged_in()) {
        // User is logged in, customize your query loop
        $args = array(
            'post_type' => 'page', // Adjust post type as needed
            // Add other query arguments (e.g., custom fields, user roles)
        );
    
        $query = new WP_Query($args);
    
        if ($query->have_posts()) {
            while ($query->have_posts()) {
                $query->the_post();
                // display a list of pages here
            }
            wp_reset_postdata();
        } else {
            // No pages found for the user
            echo 'No pages available.';
        }
    } else {
        // User is not logged in
        echo 'Please log in to view pages or your custom message.';
    }
    ?>
    

    I hope it helps you.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.