I use this code
error_log('Checking for duplicate offer: listing=' . $listing_id . ', user=' . $current_user_id);
// Prevent duplicate offers if desired (optional)
$listing_count = \HivePress\Models\Best_Offer::query()->filter(
[
'listing' => $listing_id,
'user' => $current_user_id, // Will map to user_id
]
)->get_count();
error_log( print_r( $listing_count , true ) );
$existing_offer = \HivePress\Models\Best_Offer::query()
->filter([
'listing' => $listing_id, // Will map to comment_post_ID
'user' => $current_user_id, // Will map to user_id
// 'status' => 'pending', // Will map to commentmeta if not a native column
])
->get();
error_log( print_r( $existing_offer->count() , true ) );
//error_log( print_r( $existing_offer, true ) );
To check for duplicate offer in the database. To confirm the values are there and valid in the query i have logged them to the error log:
There is one record in the wp_commments table with the type==best_offer:
The comment_post_id (0) in the table does not match the listing of the filter (256), also the user does not match but it is outside the screenshot.
Considering i used 2 diffrent approaches with the same results (the return of the only 1 record in the table), the filter seems to not do its job. What am i doing wrong?
Edit ot add the model:
// Define the model fields.
'fields' => [
'price' => [
'type' => 'number',
'label' => 'Offered Price',
'required' => true,
],
'message' => [
'type' => 'text',
'label' => 'Message',
],
'sent_date' => [
'type' => 'date',
'format' => 'Y-m-d H:i:s',
'time' => true,
'_alias' => 'comment_date',
],
'status' => [
'type' => 'text',
'label' => 'Status',
'default' => 'pending', // pending, accepted, declined, countered
],
'listing' => [
'_alias' => 'comment_post_ID',
'type' => 'link',
'model' => 'listing',
'label' => 'Listing',
'required' => true,
],
'user' => [
'_alias' => 'user_id',
'type' => 'link',
'model' => 'user',
'label' => 'User',
'required' => true,
],


