Question

I am running an fgetcsv query to import a bunch of data from a CSV into WordPress.

I am wondering how I can start an auto increment from a certain number, for example, from 1000 onwards.

$import1="INSERT into wp_postmeta (meta_id,post_id,meta_key,meta_value) values(',',',','first_name','$data[1]')";

This is an example of the code. the meta_id should use a normal auto increment, but the post_id I want to start from a certain number.

How would I accomplish this?

Was it helpful?

Solution

To set the starting value for an auto increment field, you can use alter table

ALTER TABLE wp_postmeta AUTO_INCREMENT = 1000;

As far as I know, it is not possible to have two auto incrementing fields on the same table in mysql, so you have to do it progamatically yourself (eg with a trigger)

OTHER TIPS

To change the AUTO_INCREMENT value on the table:

ALTER TABLE wp_postmeta AUTO_INCREMENT = 1000;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top