1

So, I have following wpdb DELETE function:

$wpdb->delete( $table, array( 'sub_id' => $sub_id ) ????);  

I want to delete rows where WHERE two conditions are met

For example, when sub_id = $sub_id AND date = $date, then I want to delete a row where these two conditions are available.

How do I change above function?

Thanks

2 Answers 2

1

You can go in this direction:

$wpdb->query("DELETE FROM table_name WHERE 'sub_id'=".$sub_id." AND date=".$date);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply. And yeah, I didn't find any info other this method. Thanks
1

If you want to use multiple where conditions, than the second parameter should be a associative array. The conditions will be joined with "AND".

$wpdb->delete($wpdb->prefix . 'table_name', array('sub_id' => $sub_id, 'date' => $date));

Following query will be generated: DELETE FROM wp_table_name WHERE sub_id = 1 AND date = 2017-07-17 00:00:00

For more info look here: DELETE Rows

Comments

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.