Import Issues

This topic contains 36 replies, has 3 voices, and was last updated by  Anitra Larsen 4 years, 3 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #518131

    Anitra Larsen
    Full Member
    Post count: 52
    This reply has been marked as private.
    #518248

    Kiran
    Moderator
    Post count: 7069
    This reply has been marked as private.
    #518378

    Anitra Larsen
    Full Member
    Post count: 52

    Kiran,

    Great! I see the images too for your test. I’ll give this a try with some of my imported listings tomorrow. (Sorry I was on the road today so I had no office time…)

    Any chance the assigning of old images to the new post ID can be built into the import script, so I don’t have to go through the work of doing this in the database for 500+ listings? Maybe there’s a work around of some sort? I’m not an advanced coder, so I’m not sure what might work… but maybe I can assign new post IDs at import so the images get added to the attachments table?

    If this is beyond the scope of your support, perhaps I can pay for it? It would be worth some money to have this automated!

    #518380

    Alex Rollin
    Moderator
    Post count: 27815

    I have taken that up as a suggestion. If you are looking for hands on help to migrate listings you can find that here:
    https://geodirectoryexperts.com/

    #518381

    Anitra Larsen
    Full Member
    Post count: 52

    Alex,

    Can you ask Kiran to respond to this since he’s been working on it?

    Thanks!

    Anitra

    #518382

    Alex Rollin
    Moderator
    Post count: 27815

    Certainly, when he is back in the office.

    #518383

    Anitra Larsen
    Full Member
    Post count: 52

    Great! Thank you. I will await Kiran’s reply. Have a great day!

    #518566

    Kiran
    Moderator
    Post count: 7069
    This reply has been marked as private.
    #518619

    Anitra Larsen
    Full Member
    Post count: 52

    Hi Kiran,

    I’ve imported 40 listings in to the gd_restaurants CPT (the others go into some of the other new CPTs I’ve created).

    I’m not sure if it would help you to have the import file, so I have attached it below. Note: I imported with blank ID fields, but the attached is the file before I deleted the original post_id. It seems having that might be helpful for this project.

    #518732

    Kiran
    Moderator
    Post count: 7069

    Hi Anitra,

    Please check now. Here is PHP snippet to move attachments from one CPT to another CPT.

    
    
    /**
     * Move attachments after moving listings from one CPT to another CPT.
     *
     * 1) Add this PHP snippet in child theme functions.php file or add via snippet plugin.
     * 2) Go to https://www.YORSITE.COM/?___gdmerge=1
     * 3) Click on GO
     */
    function gd_snippet_191126_move_cpt_attachments() {
    	global $wpdb;
    
    	if ( empty( $_GET['___gdmerge'] ) ) {
    		return;
    	}
    
    	$old_post_type = 'gd_place';  // Old post type.
    	$new_post_type = 'gd_restaurant';  // New post type.
    
    	$results = $wpdb->get_results( "SELECT old.post_id AS old_post_id, new.post_id AS new_post_id, new.post_title FROM {$wpdb->prefix}geodir_{$new_post_type}_detail AS new INNER JOIN {$wpdb->prefix}geodir_{$old_post_type}_detail AS old ON ( old.post_title = new.post_title AND old.post_status = new.post_status AND old.street = new.street ) ORDER BY old.post_id ASC" );
    
    	if ( ! empty( $results ) ) {
    		echo count( $results ) . ' POSTS FOUND</br></br>';
    
    		if ( (int) $_GET['___gdmerge'] === 2 ) {
    			$count = 0;
    			foreach ( $results as $row ) {
    				$result = $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->prefix}geodir_attachments SET post_id = %d WHERE post_id = %d", array( $row->new_post_id, $row->old_post_id ) ) );
    
    				if ( $result ) {
    					$count++;
    					echo $count . ' ) ' . $row->old_post_id . ' => ' . $row->new_post_id . ' ( ' . $row->post_title . ' )</br>';
    				}
    			}
    			echo $count . ' POSTS PROCESSED</br></br>';
    		} else {
    			echo '<a href="' . esc_url( add_query_arg( '___gdmerge', 2, remove_query_arg( '___gdmerge' ) ) ) . '">GO</a>';
    		}
    	} else {
    		echo 'NO POSTS FOUND</br></br>';
    	}
    
    	exit;
    }
    add_action( 'init', 'gd_snippet_191126_move_cpt_attachments', 20 );

    Regards,
    Kiran

    #518760

    Anitra Larsen
    Full Member
    Post count: 52

    That’s AMAZING! Thank you so much. I’ll work on my imports tomorrow and report back on how everything goes! Kiran – You’ve been so helpful. I’m so thankful for you!

    #518919

    Anitra Larsen
    Full Member
    Post count: 52

    I just imported all of my listings and ran your script above. This worked wonderfully! Thank you so so much!

    #518920

    Anitra Larsen
    Full Member
    Post count: 52

    Can I have you look at one more thing for me? Let me know if this should be a new thread!

    I’m having issues with Open Street Maps.
    – For example, I’m trying to create a new listing at 1350 320th Ave.
    Estherville, IA Iowa 51334 (which is also the existing address for listing https://vacationokoboji.com/places/little-swan-lake-winery/) but I get this error: “Cannot determine address at this location.”

    – Also, I cannot set addresses to Milford, Iowa (zip 51351) – it defaults to Dickinson County when I type in Milford, but Dickinson County is not the town…

    It might be helpful to know, we switched from using Google Maps to Open Street Maps earlier this year because Google’s fees were too high.

    #518956

    Alex Rollin
    Moderator
    Post count: 27815

    OSM does not seem to have any awareness of that address:
    https://www.openstreetmap.org/search?query=1350%20320th%20Ave%20Estherville%2C%20Iowa%2C%20United%20states#map=19/52.47905/13.42595

    OSM’s db is outside of our sphere of influence, unfortunately. Read more about Google vs OSM here:

    https://wpgeodirectory.com/docs-v2/integrations/google/#osm

    If you have a Google geocoding key you can use this to force use of Google maps on the add listing page:

    
    
    
    /**
     * Load Google map on add listing page.
     */
    function gd_snippet_map_name( $map ) {
        if ( geodir_is_page( 'add-listing' ) ) {
            $map = 'google'; // google or osm
        }
        return $map;
    }
    add_filter( 'geodir_map_name', 'gd_snippet_map_name', 20, 1 );
    
    #519571

    Anitra Larsen
    Full Member
    Post count: 52

    Sorry, that didn’t work for us. It seems it’s still loading OSM on the admin listing page.

    Is there a snippet to load google maps in the ADMIN add/edit listing pages too? We only add listings via the the admin…

Viewing 15 posts - 16 through 30 (of 37 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket