How to use update and delete query in wordpress

admin

Administrator
Staff member
First i write manually update, delete, insert and select query and execute data with
Code:
mysql_query
function

Like this:

Select query

Code:
$prefix = $wpdb->prefix;
$postSql = "SELECT DISTINCT post_id
            FROM " . $prefix . "postmeta As meta
            Inner Join " . $prefix . "posts As post
            On post.ID = meta.post_id
            Where post_type = 'product' 
            And post_status = 'publish'
            And meta_key Like '%product_img%'";
$postQry = mysql_query($postSql);
while ($postRow = mysql_fetch_array($postQry)) {
     $post_id = $postRow['post_id'];
}

Insert Query

Code:
$insert_images = "Insert Into " . $prefix . "postmeta(post_id,meta_key,meta_value) Value('$post_id','$meta_key','$data_serialize')";
        mysql_query($insert_images);

Update Query:

Code:
$update_price = "Update " . $prefix . "postmeta
                         Set meta_key = 'wpc_product_price'
                         Where post_id = $supportMetaID
                         And meta_key Like '%product_price%'";
 mysql_query($update_price);

Delete Query

Code:
mysql_query("Delete From " . $prefix . "postmeta Where meta_key IN ('product_img1','product_img2','product_img3')");

All queries are working perfectly ... but now i want to embed all queries in wordpress queries.

I can also use wordpress queries like

Code:
$wpdb->get_results( "SELECT id, name FROM mytable" );
$wpdb->insert( 
    'table', 
    array( 
        'column1' => 'value1', 
        'column2' => 123 
    ), 
);
$wpdb->update( 
    'table', 
    array( 
        'column1' => 'value1',  // string
        'column2' => 'value2'   // integer (number) 
    ), 
    array( 'ID' => 1 )
);
$wpdb->delete( 'table', array( 'ID' => 1 ) );

But you can see that i use
Code:
and / or
conditions in my queries. So any body help me how can i embed my queries in wordpress