It seems like the crux of the question is this:
This causes the first ‘if’ condition to return TRUE and it inserts a
duplicate post.
Check for the post_name
instead. That value is normalized to lowercase and dashes by sanitize_title_with_dashes
so you won’t have this issue. That value is also the one that WordPress enforces as unique, and the one used as a permalink.
Related Posts:
- Inserting Hundreds of Thousands of Posts at Once
- How many ‘wp_insert_post’ calls can be performed in one shot, in a very long ‘for’ loop?
- Insert two row in wordpress database
- Access denied for user ‘root@localhost’ (using password:NO)
- MySQL error 2006: mysql server has gone away
- Which MySQL data type to use for storing boolean values
- “INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”
- PHP Connection failed: SQLSTATE[HY000] [2002] Connection refused
- #1273 – Unknown collation: ‘utf8mb4_unicode_520_ci’
- Your password does not satisfy the current policy requirements
- MySQL: Access denied for user ‘test’@’localhost’ (using password: YES) except root user
- PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP
- what does “/index.php?admin/admin_dashboard” in my url mean
- How to join two tables by multiple columns in SQL?
- How to get size of mysql database?
- Selecting data from two different tables without using joins
- SQL – Update multiple records in one query
- MySQL Error 1093 – Can’t specify target table for update in FROM clause
- mysqladmin: connect to server at ‘localhost’ failed
- mysql update multiple columns with same now()
- Usage of MySQL’s “IF EXISTS”
- How can I loop through all rows of a table? (MySQL)
- Generating a random & unique 8 character string using MySQL
- MySQL > Table doesn’t exist. But it does (or it should)
- SQL select only rows with max value on a column
- Getting java.sql.SQLException: Operation not allowed after ResultSet closed
- mysql count duplicates
- phpmyadmin #1045 Cannot log in to the MySQL server. after installing mysql command line client
- MySQL config file location – redhat linux server
- How to create a foreign key in phpmyadmin
- Can’t create test file lower test start server mysql
- MySQL delete multiple rows in one query conditions unique to each row
- Create boolean column in MySQL with false as default value?
- SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
- CAST to DECIMAL in MySQL
- Error Code 1292 – Truncated incorrect DOUBLE value – Mysql
- MySql – HAVING vs WHERE
- How to stop mysqld
- Is merge statement available in MySQL
- GROUP_CONCAT comma separator – MySQL
- Failed to Connect to MySQL at localhost:3306 with user root
- How do you properly prepare a %LIKE% SQL statement?
- WordPress MySQL & PHP Performance
- SQL query to update post_date (one post = one single date & time)
- My WordPress site always displays a cached version of its homepage
- Updating User Meta with SQL Query
- wpdb prepare syntax
- How to run this SQL query of wp_terms database
- How to copy post titles to post slug in phpmyadmin
- If I consider changing my WordPress DB tables to InnoDB, will it have an effect on the way WordPress works?
- wp_admin edit.php slow with lots of queries
- Database: Custom table: sprintf value for DateTime column
- can database and media folder be moved to a different drive?
- What is the most secure way to set up the MySQL user in WPMU?
- WP_USE_EXT_MYSQL
- writing inner join in wpdb
- How to get data from WordPress site sql file
- Unknown collation when I import a dump from an existing site into a development database?
- PHP script can’t connect to Database on port 3307
- WordPress with php5-fpm and nginx
- Migrating from Existing MySQL Setup to WordPress
- How to split the a table in database?
- When WordPress Default table, Echo Success. When Plugin Table, Echo Blank
- How to translate this mySQL query to $wpdb query
- $wpdb to insert html form information
- Proper usage of $wpdb->update()?
- MySQL 5.5 upgrade ‘broke’ WordPress [closed]
- Separate DB by yearly archive of WordPress
- What should a WordPress developer know about MySQL? [closed]
- Copyright: Get first and last date of post type
- Update MySQL query so that it functions again
- Query posts by custom taxonomy and sort by post_modified
- WordPress $wpdb get posts from category and sort by custom meta
- WordPress tables and aliases?
- What’s the sql for this condition?
- Copy usermeta value where ID matches in the same table
- Array Formation Issue
- How can I write a formal sql query to get data from a custom table
- Migration problems with mysql: Operation not allowed when innodb_forced_recovery > 0 [closed]
- WordPress $wpdb no result
- when using $wpdb sudden connection rejection without changing anything. Access denied, with errors from repair tool
- How to run SQL query from WordPress ‘WP Crontrol’ plugin
- edit_user_created_user hook – using to update Groups
- Changes not being reflected on new server
- Mysql Error in querying form entries in Gravity Form plugin
- Improving performance of SQL sub-queries in WordPress
- MySQL – How to combine data from two tables into one?
- Saving custom term value to the database in new table
- Stop my loop to register data twice
- MySQL errors after a WordPress clone
- MYSQL Join on meta key value?
- Woocommerce: Grab total revenue of a product over all orders
- Complicated MySQL Query
- problem with quotes on new post
- SQL Database Lost
- Initialization of table in database using ‘CREATE … IF NOT EXISTS’
- mysqldump throws: Unknown table ‘COLUMN_STATISTICS’ in information_schema (1109)
- How do I load a sql.gz file to my database? (importing)
- How to find source of these strange SQL queries?
- Batch Replace URLs in WordPress Database