GEO my WP Support

Use this forum for technical support and general questions related to GEO my WP plugin and its core add-ons only. For technical support and general questions related to any of the premium extensions please open a new premium support ticket.

[Not resolved]WP All Import to import Fields into GeoMyWP

Home Forums Support WP All Import to import Fields into GeoMyWP

This topic contains 13 replies, has 4 voices, and was last updated by  kory 2 years, 9 months ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #54953

    Pascal Klingler
    Participant

    Hi, I am using the plugin “WP All Import” to import a .csv-file. Now I want to import fields into geomywp (like street, zipcode, etc.)

    Can somebody help me or how can I get the names of the meta fields for street, zipcode, etc?

    Thanks,
    Pascal

    #54965

    Eyal Fitoussi
    Keymaster

    Hello Pascal,

    GEO my WP holds the locations information in its own database table named wp_places_locator ( for posts ) and wp_friends_locator ( for BuddyPress members ).

    Now, If the locations that you are importing contains the coordinates then you will need to import the location information into GEO my WP database table together with each post ID or Member ID.

    However, if coordinates do not exists in the CSV file, then you will need to write a script that geocode each address before it is being imported, then save the location data in GEO my WP’s database table.

    I hope that helps a bit.

    Let me know if you have any other questions.

    #54972

    Pascal Klingler
    Participant

    Hi Eyal,
    thanks for your feedback 🙂

    I have custom fields integrated with advanced custom fields:

    – Street
    – Zipcode
    – Address
    – etc.

    Is it possible to use this values from this fields to integrate it into geo my wordpress?

    Is there any code example for it? I have seen that I can updated geo my wordpress values. But I don’t know how it works… can you help me?

    Thanks,
    Pascal

    #54982

    Paul
    Participant

    Hi Pascal,

    Eyal helped me out with this very same issue not so long ago (thanks Eyal!!!) and I managed to get it working. I figure the least I can do is try to help you out as well.

    Keep a couple of things in mind:
    1) The following is for Buddypress Member locations, not posts.
    2) I am still pretty new to PHP so I am sure there are 50 better ways to do what I did. But it works for me.

    First, read this thread: https://geomywp.com/forums/topic/import-members/

    The function gmw_update_user_location() is what we’ll be using to geocode the member’s location on import. From what I can tell, there are two ways to do this:

    1) Find a hook in WP All Import plugin that “runs” after each imported member. You need to use this hook to “execute” a function that will “grab” the address of the imported member, geocode this address and save the data in the database.
    Since I used Import Users From CSV With Meta plugin, I didn’t have such a hook. So I had to go with option 2.

    2) I copied all the file contents from geo-my-wp/includes/geo-my-wp-user-update-location.php into my child theme’s functions.php
    Then I called the function directly from within the importer while passing the user ID (already defined in the importer php file) and the address that was ti be uploaded fom the CSV file into a BP XProfile text field called Mailing Address (in the format: 12 Example Street Suburb State Zipcode Country):

    Hopefully this can get you started!

    #54983

    Paul
    Participant

    The code didn’t really come out too well in the last reply.
    Here it is again without the code tags:

    #54984

    Pascal Klingler
    Participant

    Hi, thanks a lot. I will test it 🙂

    #54998

    Eyal Fitoussi
    Keymaster

    @medievilmusician you are welcome, I am glad I could help. And thank you for sharing your solution. However, I think Pascal need to integrated custom fields rather than BUddyPress members.

    @pascal, it is not possible to use the location saved in custom fields directly with GEO my WP for the location search.

    How exactly the location fields are being added to the posts of your site? using a form in the front-end or in the back end? to using any other method?

    #55008

    Pascal Klingler
    Participant

    Hi,

    I have created a custom post type “kirchen” and included the geo my wordpress plugin for this post type. Now I have created custom fields with the “advanced custom fields” plugin (ACF).

    I’m using the plugin “WP All Import” to create new posts. I have created a .csv-file with some values to create new posts.

    Now I want to import the .csv-file and want to created some new posts.

    With the plugin “WP All Import” I can import the values from my .csv-file as values for ACF (look at the screenshot as attachment).

    All the posts created new after import. Is it possible to create a new post, set values to custom fields (ACF) and after saving, the values from ACF connected with geo my wordpress… also use the values from ACF for geo my wordpress.

    Or where can I find the custom fields meta for the fields from geo my wordpress like street, location, zipcode, etc.

    Attachments:
    You must be logged in to view attached files.
    #55010

    Pascal Klingler
    Participant

    Here is another screenshot from the import plugin. Here I can set special meta fields for import. But I don’t know the meta fields for geo my wordpress. Where can I find this fields (names)?

    And I can insert a function for import. I want to set the values from my CSV-File into geo my wordpress.

    And my ACF fields are:

    – acf_street (ex. Musterstrasse)
    – acf_zipcode (ex. 12345)
    – acf_location (ex. Musterhausen)

    Hope you can help me 🙂

    Attachments:
    You must be logged in to view attached files.
    #55017

    Eyal Fitoussi
    Keymaster

    Hello Pascal,

    GEO my WP does not save the geolocation information in custom fields. Rather, it is being saved in a custom table in database – wp_places_locator. So unless the importer can import data into a custom table, you will need to find another way to import the locations.

    All the posts created new after import. Is it possible to create a new post, set values to custom fields (ACF) and after saving, the values from ACF connected with geo my wordpress… also use the values from ACF for geo my wordpress.

    No, it is impossible to use GEO my WP with location saved in custom fields directly. Below are solutions that you could probably use:

    1)For posts created in the admin or the front-end, and address is entered using custom field, you can use this function to geocode the address from the custom field and save it into GEO my WP database table. This will make the posts searchable via GEO my WP

    2) For importing – if the CSV file was also contains the latitude and longitude of the locations, you could then import the location fields from the file into the custom fields. And then use of GEO my WP importers ( can be found in Dashboard -> GEO my WP -> Tools ) to import the locations from the custom fields into GEO my WP table in database.

    Since it looks like that the coordinates don’t exist in the CSV file, you will need to do something similar to what @medievilmusician suggested above. You will need to hook into the importer and geocode each address as it is being imported and save it into GEO my WP database table.

    What you are trying to create is most likely possible. But will require some custom functions using action hooks and filters.

    I hope that helps.

    #55042

    Pascal Klingler
    Participant

    Hi, thank you very much!

    Can you give me a example code for gmw_pt_update_location? I don’t know how I have to modificate this functions for my own.

    I have a created a custom field with “advanced custom fields”. It’s a single field for the “address”.

    In this field I insert a address like this:

    Lessingstrasse 8, 67454 Hassloch, Germany

    This custom field (ACF) can I insert in my template with this code:

    <?php the_field(‘acf-address’);?>

    Now, can you give me the functions, so I can save this custom field to geomywp database table?

    Thanks a lot,
    Pascal

    PS: Sorry I don’t know how to use this function “gmw_pt_update_location”

    #55049

    Eyal Fitoussi
    Keymaster

    The best example I can provide you with is the first example on the documentation page. You only need to modify this functions based on your needs and custom field.

    #55062

    Pascal Klingler
    Participant

    Hi, I have insert this code in my functions.php:

    function gmw_update_post_type_post_location( $post_id ) {

    // Return if it’s a post revision
    if ( false !== wp_is_post_revision( $post_id ) )
    return;

    // check autosave //
    if ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) {
    return;
    }

    //check if user can edit post
    if ( !current_user_can( ‘edit_post’, $post_id ) )
    return;

    //get the address from the custom field “address”
    $address = get_post_meta( $post_id, ‘adresse-strasse’, true );

    //varify that address exists. Otherwise abort the function.
    if ( empty( $address ) )
    return;

    //include the update location file file
    include_once( GMW_PT_PATH .’/includes/gmw-pt-update-location.php’ );

    //make sure the file included and the function exists
    if ( !function_exists( ‘gmw_pt_update_location’ ) )
    return;

    //Create the array that will pass to the function
    $args = array(
    ‘post_id’ => $post_id, //Post Id of the post
    ‘address’ => $address // the address we pull from the custom field above
    );

    //run the udpate location function
    gmw_pt_update_location( $args );
    }
    //execute the function whenever post type is being updated
    add_action( ‘save_post_post’, ‘gmw_update_post_type_post_location’ );

    But it’s not working. Can you help me please? I use a custom post type called “kirchen”.

    Hope you can help me soon… 🙁

    #55198

    kory
    Participant

    I believe that if you change:

    add_action( ‘save_post_post’, ‘gmw_update_post_type_post_location’ );

    to:

    add_action( ‘save_post’, ‘gmw_update_post_type_post_location’ );

    it will work.

Viewing 14 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic.