Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Importing data into serialized array in Wordpress

Posted on 2014-10-20
4
Medium Priority
?
627 Views
Last Modified: 2014-12-18
I have creating website for a basketball league. I used Formidable Pros for the front end registration and payments. I am now using sportpress pro to set up players, teams, schedules,etc. I created  a csv file that I was going to import in sportpresspro database but found out they are not using tables but postmeta data instead of tables. Is there a way to import my data into this array. Thanks
0
Comment
Question by:Hidesign
  • 2
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40392690
Almost all plugins that store data will store it as key-value pairs in some meta table.  Formidable does this, Gravity does this, etc.

What you think of when you want to import is a single CSV into a vanilla row/column format table and obviously that won't quite work if the plugin has no import routine.  What you need to do instead is figure out the structure of the meta tables in play and run a series of imports via MySQL to fully upload your data.

For example, assuming the plugin creates a custom post type then you need to figure out what gets posted in the wp-posts table (probably the team).  From there do a simple insert query to add all teams to wp-posts and then extract the ID numbers.  From there you can build queries that create new rows in whatever tables are needed, making sure to include the post ID number when necessary.
0
 

Author Comment

by:Hidesign
ID: 40392789
Thanks - the plugin does come with an import feature but it only imports 7 set fields. I wanted other fields in addition so I don't have to retype them. I want to import the players with height, weight, grade and contact info. One of the preset fields is postion and I was thinking about putting the grade in that field if I can figure out how to change the text in the backend to say grade instead of position.

I was looking through the wp_postmeta table to see how it laid out. There is so much data that is not related to the players so I'm sure how to update.
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 2000 total points
ID: 40392952
It's not the easiest thing in the world to see unless you are very familiar with WordPress and, furthermore, wp_postmeta is not the only thing in play here.  I'll try to explain:

wp_postmeta has four columns:

meta_id = autoincrementing primary key
post_id = the ID of the post this meta relates to
meta_key = the name of the meta item
meta_value = the value of the meta item

This construction means you can have a one-to-many relationship between a post item (which are a custom post type) and postmeta.  Postmeta is primarily used for custom fields...so anything in this system that appears in postmeta can be replicated/updated by query.  To determine what is in postmeta, go to the All [Whatever] screen and hover over any edit link.  In the URL will be an ID number for that team.  That's the post_id.  Search for that in postmeta:

SELECT * FROM wp_postmeta WHERE post_id = X

Open in new window


and you will see how the custom fields for teams are constructed and you should be able to figure out how to manipulate from there. You just search on post_id and/or meta_key to narrow it down.

But, in all likelihood, the data you really want is stored elsewhere.

I want to import the players with height, weight, grade and contact info.

Because this is a paid plugin, I can't really see what is going on with it so I'm making some guesses here.

If players are users then that data will be in usermeta.  Same basic rules as postmeta, just different tables.  The plugin probably adds some user custom fields but you can do the same thing with some extra code in functions.php:

http://wpengineer.com/2173/custom-fields-wordpress-user-profile/

or via one of several plugins. The problem with this is that the  SportsPress plugin will not be aware of these other fields so you may end up having to hack it to get them in there properly.  I would suggest checking with their support line to find out the best way to do this.
0
 

Author Comment

by:Hidesign
ID: 40406665
Hi - thanks for the info - I'm going through it and the code to see if I can get this working. I'm hoping I can get this data imported. Will take too long to key it all in
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
The viewer will learn how to count occurrences of each item in an array.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question