WordPress.org

Support

Support » Plugins and Hacks » [Resolved] [Plugin: SimpleMap] Search shows map results but doesn't link to them?

[Resolved] [Plugin: SimpleMap] Search shows map results but doesn't link to them?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Do we know?

    Have you modified the plugin? At all? The post type should be registered to not show up in posts and I haven’t gotten this bug report before?

    Make sure that the sm-location post type is registered as publically_queryable => false

    http://plugins.trac.wordpress.org/browser/simplemap/trunk/classes/locations.php#L23

    Hi, Thank you for the reply. No, I haven’t moded the plugin.

    I notice the links also don’t work on the admin side, if I click ‘View’ on the ‘Edit Locations’ page I get the same broken link for listings. This is my sites domain name followed by;

    /?sm-location=

    With the pages title. which gives and error 404 page?

    I’ve installed this on a new WP installation, deleted everything and started from scratch with no other plugins, etc. and I’m also getting this exact scenario. I have not modified anything.

    http://goretail.ca/?sm-location=the-great-canadian-meat-company

    This is fixed in 2.3.3
    You can get an advanced version of this with premium support if you’d like, but all you need to do to fix this is to follow the instructions below (I’m giving you the entire function to replace, but its one line… you’re adding exclude_from_search = true,.

    Find this function:

    function register_locations(){
    
    	$args = array(
    		'public' => true,
    		'publicly_queryable' => false,
    		'show_ui' => true,
    		'capability_type' => 'post',
    		'hierarchical' => true,
    		'rewrite' => false,
    		'query_var' => 'sm-location',
    		'register_meta_box_cb' => array( &$this, 'location_meta_cb' ),
    		'supports' => array(),
    		'labels' => array(
    			'name' => 'Locations',
    			'singular_name' => 'Location',
    			'add_new_item' => 'Add New Location',
    			'edit_item' => 'Edit Location',
    			'new_item' => 'New Location',
    			'view_item' => 'View Locations',
    			'search_items' => 'Search Locations',
    			'not_found' => 'No Locations found',
    			'not_found_in_trash' => 'No Locations found in trash',
    		)
    	);
    	// Register it
    	register_post_type( 'sm-location', $args );
    }

    and replace it with this one

    function register_locations(){
    
    	$args = array(
    		'public' => true,
    		'publicly_queryable' => false,
                    'exclude_from_search' => true,
    		'show_ui' => true,
    		'capability_type' => 'post',
    		'hierarchical' => true,
    		'rewrite' => false,
    		'query_var' => 'sm-location',
    		'register_meta_box_cb' => array( &$this, 'location_meta_cb' ),
    		'supports' => array(),
    		'labels' => array(
    			'name' => 'Locations',
    			'singular_name' => 'Location',
    			'add_new_item' => 'Add New Location',
    			'edit_item' => 'Edit Location',
    			'new_item' => 'New Location',
    			'view_item' => 'View Locations',
    			'search_items' => 'Search Locations',
    			'not_found' => 'No Locations found',
    			'not_found_in_trash' => 'No Locations found in trash',
    		)
    	);
            // Register it
    	register_post_type( 'sm-location', $args );
    }

    Thats great Glen. I’ll update the file now.

    That’s cool – but now the search result won’t show up.

    Is it possible to enable the WordPress search result to link to the map page somehow?

    mrose17

    @mrose17

    i suspect that if you change ‘publicly-queryable’ from false to true, you will find joy.

    mirefoot

    @mirefoot

    That all worled a treat

    How do we get the listing of the locations in the search result to link to the actual custom post?

    mrose17

    @mrose17

    if we are talking about simplemap 2.2.5, then:

    step 1: get the search helper to include the permalink in the results, that’s easy:

    --- _xml-search.php	2011-07-27 20:07:22.000000000 -0700
    +++ xml-search.php	2011-09-24 00:26:21.000000000 -0700
    @@ -205,6 +205,7 @@
     						$newnode 	= $markers->addChild( 'marker' );
     					}
    
    +					$newnode->$attr_func( "plink", esc_attr( get_permalink( $location->ID ) ) );
     					$newnode->$attr_func( "name", apply_filters( 'the_title', $location->post_title ) );
     					$newnode->$attr_func( "description", apply_filters( 'the_content', $location->post_content ) );
     					$newnode->$attr_func( "lat", esc_attr( $location->lat ) );
    @@ -240,6 +241,7 @@
     				$markers = array();
     				foreach ( $dataset as $key => $location ) {
     					$fields = array(
    +						'plink' => esc_attr( get_permalink( $location->ID ) ),
     						'name' => apply_filters( 'the_title', $location->post_title ),
     						'description' => apply_filters( 'the_content', $location->post_content ),
     						'lat' => esc_attr( $location->lat ),

    step 2: make use of it in classes/simplemap.php – i’m not including the code for this (because i’m not satisfied with the changes i’ve made); however, here’s what to do:

    go to the javascript function searchLocationsNear(). you’ll see this:

    for (var i = 0; i < markers.length; i++ ) {
    						var name = markers[i].getAttribute('name');

    add a new variable there:

    var plink = markers[i].getAttribute('plink');

    later on you will see two calls that look like this:

    var marker = createMarker(...);
    ...
    varsidebarEntry = createSidebarEntry(...);

    add plink as a parameter to each them. then scroll down the file until you find these two javascript functions. add the parameter to each and then make use of it however you want.

    for example, instead of putting up the website url you could put up a link that says “More Details” with the permalink.

    finally, although i have had great success making a few changes and fixing a few minor bugs with this plugin, i’m probably going to move to the premium version soon, simply because i don’t want to have to keep backporting the diffs.

    mirefoot

    @mirefoot

    Thank you so much, it all works great.

    For anyone else, this is the finished line after making the changes described above…

    html += '<h3 style="margin-top: 0; padding-top: 0; border-top: none;"><a href="' + plink + '">' + name + '</a>';

    I love to see community support. Thanks for the code. The 2.4 beta is available to premium subscribers and includes the ability to change the permalink slug and automatically place location data on that page once you get there.

    2.4 will eventually make it to .org/extend…

    mirefoot

    @mirefoot

    When you say automatically puts location data on the location page, do you mean I can add a map of the single location that thislocation post refers to as that is my next challenge…

    How do I put a map of the single location on that location’s page?

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘[Resolved] [Plugin: SimpleMap] Search shows map results but doesn't link to them?’ is closed to new replies.