remove missing image attachments
Try this: $imgs = get_posts(“post_type=attachment&numberposts=-1”); foreach($imgs as $img){ $file = get_attached_file($img->ID); if(!file_exists($file)){ wp_delete_post( $img->ID, false ); } }
Try this: $imgs = get_posts(“post_type=attachment&numberposts=-1”); foreach($imgs as $img){ $file = get_attached_file($img->ID); if(!file_exists($file)){ wp_delete_post( $img->ID, false ); } }
I think s_ha_dum is in the right track, but I think he got it backwards. You want to: develop/design locally connect to the REMOTE database and work with his content? You need a remote (staging) installation of WordPress, where the client can create/enter his content. You need your local WordPress site (localhost) to point to … Read more
General speaking yes for read-only applications (until MySQL 5.7, it’s deprecated since version 8.0), it enables equal SELECTs to return data extremely fast if identical calls are already stored in cache. You should consider that: Only exact same clauses can benefit from the cache engine (no spaces, no comments, no actual differences in WHERE expressions); … Read more
Yes, you can store your data in your own tables in WordPress database. There are few things that you need to take care of: Make sure your data can’t be really represented using the built-in WordPress content types. Prefix your tables with WordPress Prefix + your prefix. WordPress table prefix is $wpdb->prefix. Use the global … Read more
You answered your own question. You need to include the upgrade.php file which contains that function. Otherwise won’t be loaded on your plugin update and the function won’t exist. require_once(ABSPATH . ‘wp-admin/includes/upgrade.php’);
the wp_posts include all post types (post, page, custom post..), and to differentiate between them there is a field called post_type used to specify the name of the current entry whether it’s a page, post or a custom post. Query below will get list of pages SELECT * FROM wp_posts where post_type=”page”;
WordPress will not do any data sanitization for you. It does do sanitization/validation of the default options. You have to pass in the third argument of register_setting and either role your own validation callback or or use one of the builtins. If your options is only going to contain a string, you could do something … Read more
When working with database in WordPress you should never use the low lever mysql_* or mysqli_* functions. Always use $wpdb methods, in your case you should use prepare(): $query = $wpdb->prepare( “SELECT post_title from $wpdb->posts WHERE post_title LIKE %s”, “%” . $myTitle . “%” ); Moreover, once you are getting a single column, you have … Read more
I can’t use $wpdb->prepare, since I want to be able to add variables to my query string that look something like: $var = “AND pm.meta_value=”%$_POST[“val’]%'”; To get a literal % to pass through $wpdb->prepare just double it. You don’t need to be avoiding $wpdb->prepare. Proof of concept: var_dump($wpdb->prepare(‘SELECT * FROM {$wpdb->posts} WHERE post_title LIKE “%%%s%%”‘,’Hello’)); … Read more
Why not use the SELECT INTO OUTFILE syntax: $wpdb->query(“SELECT * INTO OUTFILE ‘/path/to/file’ FIELDS TERMINATED BY ‘\t’ LINES TERMINATED BY ‘\n’ FROM tracking”);