Support Forum
Support › MB Custom Table › MB Custom Table beginner questionsResolved
Hi Anh,
I have a few beginner question about the MB Custom Table extension. I followed the docs and created a new table.
Thanks in advance!
Hi Anh,
Just a quick reply to my original question. I'm using phpMyAdmin to import my csv file for my MB custom table fields. I've got everything set up correctly but on import I get this error message. #1062 - Duplicate entry '0' for key 'PRIMARY'
. Assuming it's associated with the ID field not getting auto generated.
How can I get an auto generated ID field so that I can import my data?
Thanks in advance!
Hi Anh,
I set the field ID to AUTO_INCREMENT. This allowed me to import my csv file and everything in the custom mb table imported correctly. But when I go to my custom post type in wp admin these listings do not show. This is driving me bananas.
How do I import a csv file for my custom post type that is using MB Custom Table?
Thanks!
Hi Brian,
Once the table is created should I delete this code?
It's fine if you delete the code. If you keep the code, it will check for table existence before trying to create.
If your data set is large do you advise setting all your fields to VARCHAR(length) NOT NULL
Varchar is for a text that you don't know the length. It's usually used for fields like title, short description. If the field is large, I'd recommend using TEXT
.
What's the best way to import xml or csv data into my newly created custom post type that uses the mb custom table?
I set the field ID to AUTO_INCREMENT. This allowed me to import my csv file and everything in the custom mb table imported correctly. But when I go to my custom post type in wp admin these listings do not show. This is driving me bananas.
The ID column must map the ID of the posts in the WordPress's table. Otherwise, the plugin can't know which post that a row belongs to.
I think, you need to edit the ID column first. Then using phpMyAdmin to import.
Hi Anh,
Thanks for the reply. I'm still struggling with the csv import. You are correct in that my ID column in my custom table must also have a matching entry in the wp_post table.
Is there something I can add to phpmyadmin so that on import of the csv file it also creates the needed info for each in the wp_post table?
If not do you have an alternate approach to importing the csv file?
Lastly - I'm back to the same issue of the file advance field saving the attachment as an ID and not the full url path. I'm pulling my field values into a wpDataTable and the value for the attachments are getting displayed as the ID and not a link. Is there a hook that I can add to functions.php to tell my field to output the full url path and not the ID.
Thanks for all your help!
Hi Brian,
Is there something I can add to phpmyadmin so that on import of the csv file it also creates the needed info for each in the wp_post table?
Creating a new post in the wp_posts table requires coding. So, I think this can be done with custom code only. Take a look at this tutorial on how to process a CSV file with PHP.
Is there a hook that I can add to functions.php to tell my field to output the full url path and not the ID.
File and image fields save attachment IDs in the database instead of URL. To get file URL, you can use wp_get_attachment_url function.