Real time Duplicate title check

You can hook ‘save_post’ or ‘wp_insert_post’ (both executed the same in wp_insert_post()) to check for autosaves and notify the author(s) accordingly. The checks that I would do would be to check that the author of the autosave (aka, revision) and the new autosave are not the same, check that the post title is the same … Read more

force http canonical tag on https pages

You can change it using following code, add it in your theme function.php or in plugin. remove_action ( ‘wp_head’ , ‘rel_canonical’ ) ; add_action ( ‘wp_head’ , ‘my_rel_canonical’ ) ; function my_rel_canonical () { ob_start () ; rel_canonical () ; $rel_content = ob_get_contents () ; ob_end_clean () ; echo str_replace ( “https:” , “http:” , … Read more

Why does get_users suddenly return duplicates?

Seems like a silly question, but are there exactly 2 users in the database? Or are there more. The only thing I can see happening is because you are setting to 3, it’s looping back through. Another thing to try is checking the peterpanpan user, to see if he has the custom_role twice in his … Read more

What’s the proper way to find and remove duplicate images from posts and the media library?

combining the two answer on this page, I found this worked. $args = new WP_Query(array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1 )); $loop = new WP_Query($args); while($loop->have_posts()) { the_post(); $args2 = array( ‘order’ => ‘ASC’, ‘post_type’ => ‘attachment’, ‘post_parent’ => $post->ID, ‘post_mime_type’ => ‘image’); $attachments = get_posts($args2); if($attachments) { foreach ($attachments as $img_post) { if( … Read more

How do I check for a duplicate record before inserting using wpdb

Let’s say the primary key of the table is my_part_ID. So we will check if there is any primary key value for the combination of user_ID and PL_part_ID as below $my_part_ID = $wpdb->get_var( $wpdb->prepare( “SELECT my_part_ID FROM ” . $wpdb->prefix . “pl_my_parts WHERE user_ID = %d AND PL_part_ID = %d LIMIT 1”, $user_ID, $PL_part_ID ) … Read more

What’s the best way to dedupe a table?

SELECT DISTINCT <insert all columns but the PK here> FROM foo. Create a temp table using that query (the syntax varies by RDBMS but there’s typically a SELECT … INTO or CREATE TABLE AS pattern available), then blow away the old table and pump the data from the temp table back into it.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)