MB Custom Table beginner questions
Support › MB Custom Table › MB Custom Table beginner questionsResolved
- This topic has 5 replies, 2 voices, and was last updated 5 years, 11 months ago by
Anh Tran.
-
AuthorPosts
-
May 11, 2019 at 1:37 PM #14499
Brian
ParticipantHi Anh,
I have a few beginner question about the MB Custom Table extension. I followed the docs and created a new table.- I used the add action init approach to creating the table. Once the table is created should I delete this code? Or is it ok to keep it in my functions.php file?
- 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'm a MySQL beginner so reading up. If your data set is large do you advise setting all your fields to VARCHAR(length) NOT NULL. Again beginner so advise welcome.
Thanks in advance!
May 12, 2019 at 2:14 AM #14503Brian
ParticipantHi 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!
May 12, 2019 at 6:34 AM #14505Brian
ParticipantHi 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!
May 13, 2019 at 9:23 AM #14515Anh Tran
KeymasterHi 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.
May 13, 2019 at 10:12 AM #14519Brian
ParticipantHi 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!
May 14, 2019 at 8:12 AM #14529Anh Tran
KeymasterHi 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.
-
AuthorPosts
- You must be logged in to reply to this topic.