admin管理员组文章数量:1313250
I am trying to add some data in WordPress Custom Field and via adding more direct records/data in wp_postmeta
table via SQL query. There are four column as mentioned below...
- 'meta_id' - A unique id for each entry.
- 'post_id' - The ID of the post for this metadata.
- 'meta_key' - The name of the 'key'.
- 'meta_value' - The value associated with the key.
Now I am using the below SQL query to add some more records/data.
$INSERTING_DATA = "INSERT INTO `wp_postmeta` (`meta_id`, `post_id`, `meta_key`, `meta_value`) values ('XXXXXXXXX', 'WordPress_Post_ID_No', 'WordPress_Post_Custom_Field_Name', 'WordPress_Post_Custom_Field_Value')";
So here I am able to add all my data but I want to know that what to add in meta_id
column ? Is that auto increment value so I have to leave that value and should I use below SQL query...???
$INSERTING_DATA = "INSERT INTO `wp_postmeta` (`post_id`, `meta_key`, `meta_value`) values ('WordPress_Post_ID_No', 'WordPress_Post_Custom_Field_Name', 'WordPress_Post_Custom_Field_Value')";
So Now tell me which one is correct and Ok to use. First or second...??? Also describe me that what is meta_id
in this table?
I am trying to add some data in WordPress Custom Field and via adding more direct records/data in wp_postmeta
table via SQL query. There are four column as mentioned below...
- 'meta_id' - A unique id for each entry.
- 'post_id' - The ID of the post for this metadata.
- 'meta_key' - The name of the 'key'.
- 'meta_value' - The value associated with the key.
Now I am using the below SQL query to add some more records/data.
$INSERTING_DATA = "INSERT INTO `wp_postmeta` (`meta_id`, `post_id`, `meta_key`, `meta_value`) values ('XXXXXXXXX', 'WordPress_Post_ID_No', 'WordPress_Post_Custom_Field_Name', 'WordPress_Post_Custom_Field_Value')";
So here I am able to add all my data but I want to know that what to add in meta_id
column ? Is that auto increment value so I have to leave that value and should I use below SQL query...???
$INSERTING_DATA = "INSERT INTO `wp_postmeta` (`post_id`, `meta_key`, `meta_value`) values ('WordPress_Post_ID_No', 'WordPress_Post_Custom_Field_Name', 'WordPress_Post_Custom_Field_Value')";
So Now tell me which one is correct and Ok to use. First or second...??? Also describe me that what is meta_id
in this table?
2 Answers
Reset to default 2meta_id
in postmeta
table is just an AUTO_INCREMENT id for the table, you can easily inspect that:
So, your guess is correct, you can leave it.
EDIT
Avoid raw SQL statements and introduce $wpdb
for SQL purposes. And for postmeta insertion you can see the following tutorial I found a best one:
- Reusable Custom Meta Boxes - Code.TutsPlus
You should not be using direct SQL. Consider creating a PHP script that loads WordPress core functions and uses them (see https://stackoverflow/questions/9101503/include-wordpress-core-into-own-scripts#answer-9126230 for getting an idea how to do that).
add_post_meta
update_post_meta
But if you do want to create custom SQL (if you are asking the question you are asking I highly do not recommend it), you should probably get more information on postmeta
table before doing so. Let me cover the topic for you.
First of all, let's get some overview of the table:
mysql> describe wp40.wp_postmeta;
+------------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------------------+------+-----+---------+----------------+
| meta_id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| post_id | bigint(20) unsigned | NO | MUL | 0 | |
| meta_key | varchar(255) | YES | MUL | NULL | |
| meta_value | longtext | YES | | NULL | |
+------------+---------------------+------+-----+---------+----------------+
4 rows in set (0,08 sec)
From that you can see that meta_id is auto_increment
and thus MySQL will figure out itself what value it should add. Passing simple 0
instead of real meta_id
is enough.
post_id
refers back to the post to which the meta is associated. Default is 0
but you should pass a real post_id
so you can see the meta in the custom fields editor on the post editing screen.
meta_key
is the name of a meta. Pay attention, using a name starting with underscore eg.: _hidden_meta
will hide the meta from custom field editor on edit screen.
meta_value
is a longtext and can hold any text you need. But pass it strings only! (in case of an array of other objects, you can serialize the text).
But once again, consider using add_post_meta or update_post_meta functions.
本文标签: postsWhat Is metaid In wppostmeta
版权声明:本文标题:posts - What Is meta_id In wp_postmeta? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741912694a2404538.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
add_post_meta
function? – Tom J Nowell ♦ Commented Sep 24, 2014 at 17:40