WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Importing data to custom fields - data not showing up on webpage (4 posts)

  1. microfree
    Member
    Posted 2 years ago #

    Hi

    I am trying to import data into a movie website, where I will import data into custom fields such as director, productionyear,internationaltitle, imdblink and so on. The data is from an exotic database that I have converted into a csv file. I have built MySQL queries and managed to insert all the posts, and relating categories. The posts and categories went fine and they are part of WordPress-core. I'm really happy I managed to get that far.

    But what I am having trouble with is this: Importing data into custom fields in wordpress. I know WordPress is using key-values for custom fields, and it all goes into wp_postmeta. This is documented in the WordPress Codex: http://codex.wordpress.org/Custom_Fields

    When I import the data and create new unique "meta_id" and relate to the post using "post_id" and then using key-values for the custom fields eg "director" which is the key and "Del Toro" as value. It simply doesn't show up on my website. I know this is correct because when I use the admin-frontend, this is exactly what the front-end does.

    What am I missing here? Again, when I create values in post_meta using mysql-queries the data is not showing up on the website. When I use the admin-panel and manually plot the data, it works.

    I spent weeks trying to solve this, and aalmost about to give up now

  2. microfree
    Member
    Posted 2 years ago #

    SOLVED!!!!

    Meta_id 's must be CHRONOLOGICAL and CANNOT be arbitrary (i.e. random).

    data must be inserted into wp_mf_postmeta AND wp_postmeta

    these records relate to post_id, meta_id and the key-value stores of
    the data itself such where key would be "movietitle" and value would be "Die Hard".

    I have uploaded the csv I created to do this and create the mysql queries.
    I used LibreOffice Calc to finetune the data and Toad for MySQL (by Quest, free)
    to create the MySQL queries...

    These two records need to be modified for the data to be properly inserted:
    NOTE THAT the META_ID MUST be chronological i.e. 11001, 11002 11003 per field per post
    so if meta_key is Movietitle is first then that has meta_id of 11001, if productionyear is second then that is 11002 and if country is third then that is 11003

    Also note that for the wp_mf_postmeta the fieldname is the SAME VALUE as meta_key
    from wp_postmeta , I.e. the meta key.

    INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES (346,'produksjonsar','18001');

    INSERT INTO wp_mf_post_meta ( meta_id, field_name, field_count, group_count, post_id ) VALUES ( 18001, 'produksjonsar' , 1,1 ,346 );

    The file I have used for this import is available here, if anyone
    needs to see an example of how to do this import... Again I used
    Toad for MySQL to create the SQL Queries by using the IMPORT function.

    * http://ge.tt/9Q5h4zC

    This also solves the two questions I posted on Stackoverflow and Stackexchange.

    http://wordpress.stackexchange.com/questions/37691/inserting-data-into-magicfields-using-mysql-queries

    http://stackoverflow.com/questions/8698631/importing-data-into-wordpress-magic-fields-using-mysql-queries

    Massive props to Hameedullah Khan Stackexchange, profile here http://wordpress.stackexchange.com/users/5337/hameedullah-khan , for basically providing the clue needed to find the solution.

  3. WebTechGlobal
    Member
    Posted 1 year ago #

    I try to avoid importing directly to the database however I create plugins for many users, mainly CSV 2 POST. That is the reason your post caught my attention.

    I need to consider the fact that some users may have plugins that do things with new meta data using action hooks. By inserting directly to the database I would bypass that.

    So my approach would be using functions like...

    add_post_meta()

  4. WebTechGlobal
    Member
    Posted 1 year ago #

    I totally forgot to mention my reason for reading this. As the author of CSV 2 POST I'm always on the lookout for users needs.

    I have never been asked to allow the importing of data to existing posts that were not originally created using CSV 2 POST.

    Easy enough done if the new data has the post ID or values that can be used to pair rows in a CSV file with values in post content. I suppose there are various approaches that can be taking.

Topic Closed

This topic has been closed to new replies.

About this Topic