Skip to:
Content
Pages
Categories
Search
Top
Bottom

custome query


  • priyam1234
    Participant

    @priyam1234

    i want to get only 2 comments , on load of activity page . wich i really get using my code
    “add_filter(‘bp_use_legacy_activity_query’, function ($value, $method, $args) {
    if ($method == “BP_Activity_Activity::get_activity_comments”) {
    return true;
    }
    }, 10, 3);

    add_filter( ‘bp_activity_comments_user_join_filter’, function( $value, $activity_id, $left, $right, $spam = ‘ham_only’ ) {
    // Modify the SQL query to fetch only two comments
    global $wpdb, $bp;
    $bp = buddypress();

    $xprofile_active = function_exists(‘bp_is_active’) && bp_is_active( ‘xprofile’ );

    // Initialize fullname related variables
    $fullname_select = $fullname_from = $fullname_where = ”;

    // Select the user’s fullname with the query if XProfile is active and user has filled the field.
    if ( $xprofile_active ) {
    if ( bp_has_profile() ) {
    // Get the field value if user has filled it.
    $field_id = 1; // Modify this according to your field ID.
    $field_value = bp_get_profile_field_data( ‘field=’ . $field_id );
    if ( !empty( $field_value ) ) {
    $fullname_select = “, pd.value as user_fullname”;
    $fullname_from = “, {$bp->profile->table_name_data} pd “;
    $fullname_where = “AND pd.user_id = a.user_id AND pd.field_id = $field_id”;
    }
    }
    }

    // Don’t retrieve activity comments marked as spam.
    if ( ‘ham_only’ == $spam ) {
    $spam_sql = ‘AND a.is_spam = 0’;
    } elseif ( ‘spam_only’ == $spam ) {
    $spam_sql = ‘AND a.is_spam = 1’;
    } else {
    $spam_sql = ”;
    }

    // Modify the SQL query to fetch only two comments
    $sql = $wpdb->prepare( “SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select}
    FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from}
    WHERE u.ID = a.user_id {$fullname_where}
    AND a.type = ‘activity_comment’ {$spam_sql}
    AND a.item_id = %d
    AND a.mptt_left > %d
    AND a.mptt_left < %d
    ORDER BY a.date_recorded ASC
    LIMIT 2″,
    $activity_id, $left, $right );

    return $sql;
    }, 10, 5 );”

    but it give me also count 2 , can i get original count.

    means , any activity has 10 comment then it display only 2 but give count 10

  • You must be logged in to reply to this topic.
Skip to toolbar