sql - Make product posts draft if post meta field equals value -


i have function runs daily want check if post expired (based on custom postmeta field) , if set post status draft. think have principle right there's pretty wrong syntax isn't making work correctly. function far:

function make_product_draft( ) {     global $wpdb;      $sql = "     update $wpdb->posts      innerjoin $wpdb->postmeta on $wpdb->posts.id = $wpdb->postmeta.post_id     set $wpdb->posts.post_status = 'draft'      $wpdb->posts.post_type = 'product' , $wpdb->posts.post_status = 'publish' , $wpdb->postmeta.post_type = 'expired'     ";     $wpdb->query($sql); } 

i think going wrong when this: $wpdb->posts.id? not sure correct syntax is. appreciated :)

my requirements changed since made post, following code worked me. niklaz comment, assistance pivotal in getting working right :)

function make_product_draft( ) { global $wpdb;  $sql = "update {$wpdb->posts}  inner join {$wpdb->postmeta} on {$wpdb->posts}.id = {$wpdb->postmeta}.post_id set {$wpdb->posts}.post_status = 'draft'  {$wpdb->posts}.post_type = 'product' , {$wpdb->posts}.post_status = 'publish' , {$wpdb->postmeta}.meta_key = '_product_expiry' , {$wpdb->postmeta}.meta_value < curdate() "; $wpdb->query($sql); } 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -