• I’ve this code

    $args = array(
                    'post_id' => $post_id,
                    'meta_query' => array(
                                            'relation' => 'AND',
                                            array(
                                                'key' => 'review_title'
                                            ),
                                            array(
                                                'key' => 'review_rating',
                                            )
                                        ),
                );
    
    $comments_query = new WP_Comment_Query;
    $comments_array = $comments_query->query( $args );

    It works fine, will work only if review_title AND review_rating exists. But it return only the second key, and I need to return both. How can I do that?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You must be referring to what your template or walker is displaying? WP_Comment_Query only returns comment objects, no meta values at all. It’s up to your theme’s template or walker function to get any desired meta values based on the current comment object’s ID, then output said values to the browser or concatenate to a returned string.

    The short answer is you need to edit your theme’s comment template or walker function, depending how your theme displays comments.

    Thread Starter dudo

    (@dudo)

    Hi bcworkz,
    you’re right, according to the doc WP_Comment_Query shouldn’t return meta values at all. But if I do a print_r ($comments_array) it return 1 meta value (the second one if I use and, the first if I use or). Simply don’t know why.

    Just to be safe I’ll get the needed meta value using the comment id

    Moderator bcworkz

    (@bcworkz)

    That’s what I would do. The last used value sounds like a quirk similar to where the final value in a loop shows up in a variable meant for something else. While such quirks can be taken advantage of, one is better off getting the value as intended via the comment ID ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Return multiple comment_meta keys’ is closed to new replies.