0

I'm building a threaded comment system using custom query providers. I use Bricks Builder and the Query loop it provides. I created custom query types for parent comment and replies comment. Parent comments work fine, but I can't get replies to show in the nested loop.

Current Setup:

Hub Registry (working):

add_filter('bricks/setup/control_options', 'gna_register_query_types');
function gna_register_query_types($control_options) {
    $control_options['queryTypes']['gna_comments'] = 'Comments';
    $control_options['queryTypes']['gna_comment_replies'] = 'Comment Replies';
    return $control_options;
}

add_filter('bricks/query/run', 'gna_run_custom_query', 10, 2);
function gna_run_custom_query($results, $query_obj) {
    if ($query_obj->object_type === 'gna_comments') {
        $results = gna_comments_query_handler();
    }
    if ($query_obj->object_type === 'gna_comment_replies') {
        $results = gna_comment_replies_query_handler();
    }
    return $results;
}

Parent Handler (works):

function gna_comments_query_handler() {
    global $post;
    $post_id = $post->ID;
    
    $comments = get_comments([
        'post_id' => $post_id,
        'parent' => 0,
        'status' => 'approve',
    ]);
    
    return $formatted_array; // Returns parent comments successfully
}

Reply Handler (doesn't work):

function gna_comment_replies_query_handler() {
    // How do I get parent comment ID from outer loop?
    $loop_object = \Bricks\Query::get_loop_object(); // Returns null
    $parent_id = $loop_object['id'] ?? 0;
    
    return get_comments(['parent' => $parent_id]); // Always empty
}

Bricks Structure:

Container (Query: gna_comments) ✅ Works
└─ Container (Query: gna_comment_replies) ❌ No results

Question: How do I access the parent loop's data inside a nested custom query provider? \Bricks\Query::get_loop_object() returns null in the nested handler.

Is there a different method for custom query types versus native Posts queries?

Thanks for any help!

New contributor
Orange Guy is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.