Custom Fields
Re-Envisioned
Support MB Custom Table MB Custom Table beginner questions

This topic contains 5 replies, has 2 voices, and was last updated by  Anh Tran 1 week ago.

  • Creator
    Topic
  • #14499

    Brian
    Participant

    Hi Anh,
    I have a few beginner question about the MB Custom Table extension. I followed the docs and created a new table.

    1. 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?
    2. What’s the best way to import xml or csv data into my newly created custom post type that uses the mb custom table?
    3. 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!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #14503

    Brian
    Participant

    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!

    #14505

    Brian
    Participant

    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!

    #14515

    Anh Tran
    Keymaster

    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.

    #14519

    Brian
    Participant

    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!

    #14529

    Anh Tran
    Keymaster

    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.

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.