SQL value returns blank?
In this function, I want item_id => 'A NUMBER'
. That number can be found on the corresponding table row retrieved from my database. I have tested the sql and it retrieves the intended values, but in the context of this function, it gives a blank value?
public function bp_learndash_lesson_comment_approved( $comment_ID, $comment_approved, $commentdata ) {
$comment_obj = get_comment( $comment_ID );
$post_id = $comment_obj->comment_post_ID;
$post_type = get_post_type( $post_id );
if ( 'sfwd-lessons' == $post_type && $commentdata && 1 === $comment_approved ) {
//ONLY do if is a child comment
if ( $comment_obj->comment_parent>0 ) {
global $bp, $wpdb;
$course_id = get_post_meta($post_id,'course_id',true);
$group_attached = get_post_meta( $course_id, 'bp_course_group', true );
if ( empty( $group_attached ) ) {
return;
}
if ( !bp_learndash_group_activity_is_on( 'user_lesson_comment', $group_attached ) ) {
return;
}
$user_link = bp_core_get_userlink( $comment_obj->user_id );
$parent_ID = $comment_obj->comment_parent;
$parent_comment = get_comment($parent_ID);
$parent_usermeta = get_userdata($parent_comment->user_id);
$op_user_link = $parent_usermeta->display_name; //would be great if you could set this up as a link?
$lesson_title = get_the_title( $post_id );
$lesson_link = get_permalink( $post_id );
$lesson_link_html = '<a href="' . esc_url( $lesson_link ) . '">' . $lesson_title . '</a>';
$parent_comment_id = $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE content = {$parent_comment->comment_content} AND type = 'lesson_comment'" ); // This sql retreives a numeric value.
$args = array(
'type' => 'activity_comment',
'action' => apply_filters( 'bp_learndash_user_lesson_comment_activity', sprintf( __( '%1$s replied to %2$s on lesson %3$s', 'buddypress-learndash' ), $user_link, $op_user_link, $lesson_link_html ), $comment_obj->user_id, $course_id ),
'item_id' => $parent_comment_id, // This is where I want the numeric value from the database.
'component' => $bp->groups->id,
'secondary_item_id' => $r['parent_id'],
'content' => $comment_obj->comment_content,
'comment_parent' => '1',
'mptt_left' => '',
'mptt_right' => ''
);
$activity_recorded = bp_learndash_record_activity( $args );
if($activity_recorded) {
bp_activity_add_meta($activity_recorded, 'bp_learndash_group_activity_markup_courseid', $post_id );
}
}
}
}
My apoligies if there’s a lot of information that’s unnecessary here, but I thought that it may give some context into what’s happening and what I want to achieve. Here’s the pastebin for a clearer visual on what’s happening: https://pastebin.com/4qg11phZ
So my core question is, why is the intended item_id
not recording the intended data?
Thanks!
Leave an answer
You must login or register to add a new answer .