• I was able to successfully import player images by adjusting mysql directly, and I’m trying to do the same for player metrics.

    Metrics are stored in wp_postmeta, with meta_key “sp_metrics”. But importing new entries here still leaves all metric fields blank on the corresponding edit player page.

    To troubleshoot, I filled in player metrics for a player via the edit player page, then found that entry in the database and manually changed one of the fields. Doing that has cleared all fields for the player in the edit player page.

    Would appreciate any tips at all, I have hundreds of players in my league with many metrics for each player and so I’m not able to do this manually.

    Thanks in advance!

    https://wordpress.org/plugins/sportspress/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Roch

    (@rochesterj)

    Hi!

    Are you moving your site from one site to another? Why do you have the WP database?

    Kind Regards,
    -Roch

    Thread Starter freshcreate

    (@freshcreate)

    No I’m not moving anything, I’m editing the database directly to import player metrics since there’s no way to import metrics using the plugin.

    I’ve actually just solved this myself. I’m including my solution below… it’s a bit long but it was very satisfying to figure out and maybe this will benefit someone else looking to import a ton of player metrics, instead of inputting them all manually. You will have to be comfortable with excel and have a basic knowledge of accessing your database. I do hope the amazing developers on this plugin will find a way to implement player metrics columns in the player import CSV, I bet many of the plugins users would find this really helpful.

    ————–
    My solution:
    – first import the player’s basic information using the Sportspress import tool
    – now you want to find the post ID for all these players you just imported. open wp_posts in your database and search for “sp_player” in the post_type field, export these results to CSV and open in excel
    – now you want each player in your metrics spreadsheet to have a column with their post ID. use vlookup to do this, matching using the player name
    – now the fun part. you need to create a formula to get all of the metrics in one string that the database can read. make sure you’ve created all the metrics in the Sportpress plugin settings first. the final result will look something like this:

    a:2:{s:8:”hometown”;s:8:”New York”;s:6:”height”;s:5:”200cm”;}

    let’s break this down:
    a:2 — that’s the number of metrics you have. 5 metrics would be a:5
    s:8 — that’s the number of characters for that field. in my example, hometown and new york each have 8 characters (including spaces), height has 6 and 200cm has 5

    the formula for the above example is as follows, assuming hometown data is in column A and height data is in column B:

    =”a:2:{s:8:””hometown””;s:”&LEN(A1)&”:”””&A1&”””;s:6:””height””;s:”&LEN(B1)&”:”””&B1&”””;}”

    let’s break this down:
    – use two quotation marks around the metric to create an actual quotation mark instead of closing the formula
    – use LEN() to determine the amount of characters
    – it’s confusing to explain why i used 3 quotation marks in a row where I did, if you don’t get it just trust me it works
    – just drag this formula down for all of your players and they will all have a final result that looks something like the above

    now open a new spreadsheet. let’s skip the first column for now we’ll get back to it in a minute. in the second column, paste all the player IDs. all entries in the third column will be the same: sp_metrics. the fourth column will be the result from the formula above, just paste the values of that formula.

    for the first column, first go to your database and open wp_postmeta. go to the last page of that table and find the last row. the first column is meta_id. add 1 to the number in that last row – that’s going to be your cell A1 in your new 4 column spreadsheet. fill the rest of that column out increasing by 1 each time.

    save this file as a CSV, check off the option to quote all text cells, and use ^ as your text delimiter. now go back to your database into the wp_postmeta table, import this CSV, and in the “columns enclosed with” and “columns escaped with” enter ^ instead of ”

    Plugin Contributor Roch

    (@rochesterj)

    That’s really great, thanks a lot for sharing!

    I’m sending this to our dev team as well.

    Kind Regards,
    -Roch

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Manually import player metrics using mysql’ is closed to new replies.