Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is post_name field in wp_posts in wordpress for?

Tags:

wordpress

I'm migrating an app to wordpress. We have thousands of wordpress posts that we will insert as custom_types in wordpress database. What is post_name field in wp_posts for? Can we have two records with the same post_name? Is it for friendly urls?

like image 981
user2670996 Avatar asked Oct 16 '15 12:10

user2670996


2 Answers

The post_name is the post's slug. These must be unique.

Read more about WP_Post member variables in the Codex.

like image 182
rnevius Avatar answered Nov 08 '22 21:11

rnevius


It is correct that the post_name field stores the slug. However, the post_name field does not have a UNIQUE constraint in the MySQL schema, so while it should be unique, it is unfortunately not the case that it must be unique. Developers of plugins or tools that write to this table should mind this distinction as the wp_posts table can be corrupted by inserting non-unique values into the post_name table.

I encountered the above issue while resolving a duplication caused by Advanced Custom Fields keying its field and field group definitions off of the contents of this field.

like image 34
David Cloutman Avatar answered Nov 08 '22 20:11

David Cloutman