Support » Plugin: Link Library » Importing CSV from My Database

  • Resolved Fred Atkinson

    (@fatkinson)


    I am now at a point with Link Library where I am ready to import link information from a database of links that I have on hand.

    That database has a large number of links in it. To input them one by one would be very time consuming.

    I exported that database in CSV format. Here is a small portion of the output:

    “callsign”;”sortcode”;”url”;”count”
    “AH0A”;”0A##AH”;”www.ah0a.org”;”0″
    “W0AA”;”0AA#W#”;”www.w0aa.org”;”0″
    “W0ABR”;”0ABRW#”;”www.w0abr.com”;”0″

    Obviously, I am going to have to edit the entire CSV file accordingly to achieve this. I see [under Global Options, Import/Export Links] that there is an option to ‘Import Links from CSV’ by uploading a text file.

    Here are the mechanics of the issue [as I see them]:

    The ‘callsign’ value should be imported as the ‘Add Title’ field.

    The ‘sortcode’ value should be imported as the ‘Custom Text Field #1’ which I have also named ‘sortcode’.

    The ‘url’ value should be imported as the ‘Web Address’ field.

    The ‘count’ field is superfluous. I do not need to import that value.

    If I can import that database of my links into Link Library, the most difficult part of this process is over!

    Any suggestions are welcome.

    • This topic was modified 11 months, 1 week ago by Fred Atkinson.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 16 through 23 (of 23 total)
  • Plugin Author Yannick Lefebvre

    (@jackdewey)

    Well, if you run this query in phpMyAdmin against your database, it will display all of the data you want to see. phpMyAdmin should then show you an option to export these records as a CSV file. Normally, all you should need to change are the wp_posts and wp_postmeta elements. For example, if your table prefix is wppotato_, then the query would become

    select p.post_title, pm1.meta_value as URL, 
    pm2.meta_value as sortcode
    from wppotato_posts p, wppotato_postmeta pm1, wppotato_postmeta pm2
    where p.ID = pm1.post_id
    and p.ID = pm2.post_id
    and pm1.meta_key = 'link_url'
    and pm2.meta_key = 'link_custom_text_1'
    Plugin Author Yannick Lefebvre

    (@jackdewey)

    So, did you manage to export your data in a useful format?

    Thread Starter Fred Atkinson

    (@fatkinson)

    Not yet.

    I have been very busy the last few days. Have not had the time,

    I have had a plugin developed which I now have to test. I used a developer on Freelancer.com to do it. He sent me the plugin today and I need to test it.

    It would great to export that data in a format I could easily import into my master database so this new plugin can use it.

    Regards,

    Fred

    Thread Starter Fred Atkinson

    (@fatkinson)

    Yannick,

    Do you feel like having a lash at it?

    I would be glad to make a donation to Link Library in return.

    I believe you still have administrative privileges on my Web site to do it with.

    If it can be downloaded in a way that would make it easy for me to import it into my database in the specified format, that will save me a lot of work.

    I can use Notepad++ to make minor changes, if required.

    If it can be exported so that they come out with the fields in the correct order (callsign, sortcode, url), It should be doable.

    If you can then provide me with the correct MySQL script tp accomplish this, I could do it myself from here forward.

    Regards,

    Fred

    Plugin Author Yannick Lefebvre

    (@jackdewey)

    I’ll try to cook you up a simple plugin this week-end that would live besides Link Library and allow you to export this data as a CSV.

    Thread Starter Fred Atkinson

    (@fatkinson)

    That would be neat.
    I was just looking to get the syntax of the MySQL statement hammered out.
    But hat would work as well.
    Regards,

    Plugin Author Yannick Lefebvre

    (@jackdewey)

    Hi Fred, Update to version 6.8.18, then add the following code to your theme’s functions.php file to only get the columns you’re interested in:

    add_filter( 'link_library_export_all_links', function( $link_items ) {
    
    	foreach ( $link_items as $item_key => $link_item ) {
    		foreach ( $link_item as $field_key => $link_field ) {
    			if ( !in_array( $field_key, array( 'Name', 'Address', 'Custom Text 1' ) ) ) {
    				unset( $link_items[$item_key][$field_key] );
    			}
    		}
    	}
    
    	return $link_items;
    }, 10, 2 );
    Plugin Author Yannick Lefebvre

    (@jackdewey)

    While I originally thought about making a separate plugin, I realized there was a much better way to tackle this request. Like the other block of code you added in your theme functions.php, make sure to remember that this code will need to be carried over if you change to a new theme on your site.

Viewing 8 replies - 16 through 23 (of 23 total)
  • The topic ‘Importing CSV from My Database’ is closed to new replies.