Search code examples
phpwordpresswordpress-themingwordpress-rest-api

$queryResult = new WP_Query( $args ) unknown error


since I am totally new to php i struggle with one custom function, problem is in line $queryResult = new WP_Query( $args ); since when I comment it out with the rest of function, everything works. However when it is there, page will show me no results for reservation which is strange

so function here

function getListOfUsersOnLesson($lesson_id) {

    $result = '... nikto nie je prihlásený';

    $args = array (
            'post_type' => 'rsg_reservations',
            'pagination' => false,
            'posts_per_page' => '-1',
            'meta_key' => '_rsg_reservation_lesson_id',
            'meta_value' => $lesson_id,
    );

    $query = new WP_Query( $args );
    if ( $query->have_posts() ) {
        $result = '';
        while ( $query->have_posts() ) {
            $query->the_post();

            $user_id = get_post_meta( get_the_ID(), '_rsg_reservation_user_id', true );
            $user_info = get_userdata($user_id);
            $user_email = $user_info->user_email;
            $username = get_user_meta( $user_id, 'first_name', true ).' '.get_user_meta( $user_id, 'last_name', true );

            $erroclass = '';
            if(reservationIsValid($lesson_id, $user_id)) $erroclass = '';
            else $erroclass = 'erroruser';

            $result.= '<div class="row">';
            $result.= '<div class="col-md-4 '.$erroclass.'">'.$username.'</div>';
            $result.= '<div class="col-md-6 '.$erroclass.'">'.$user_email.'</div>';
            $result.= '<div class="col-md-2"></div>';
            $result.= '</div>';
        }
    }
    wp_reset_postdata();

    return $result;

}

When NOT commented out When NOT commented out

When commented out, desired state When commented out, desired state

whole code is called by another method in a separate php file

$lesson_user_list = '';
            if(is_super_admin()) {
                $lesson_user_list = getListOfUsersOnLesson($lesson_id);
            }

Solution

  • Solved, that puece with error class seems to be a problem