• Resolved Matt

    (@mybcn)


    Hi,

    I have imported a number of Latitude and a number of Longitude numbers. Latutude goes into a field called poi_location-latitude and Longitude goes into poi_location-longitude. I have a number of Map plugins that I would like to feed these values to. Normally, they want the values in the format of “Longitude, Latitude” with the comma inbetween the values. How do I creat this so that I can get this combined field dynamically as one field? I have benn fiddeling with both POD Templates and with Creating a new read-only Field with the Advanced/Values/Set Default Value via Parameter, where the second would be smoothest, but not succeeded. Any help pointing me in the right direction, or supplying a working solution, would be much appreciated.

    Thank you for a fantastic product.

    //Matt

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Paul Clark

    (@pdclark)

    See the get_{meta_type}_metadata filter. For example:

    <?php
    
    /**
     * Cause get_post_meta( get_the_ID(), 'lat-lng', true ) to return the comma-separated combination of poi_location-latitude and poi_location-longitude.
     */
    add_filter(
    	'get_post_metadata',
    	function( $check, $object_id, $meta_key ) {
    
    		if ( 'lat-lng' === $meta_key ) {
    			return sprintf(
    				'%s,%s',
    				(float) get_post_meta( $object_id, 'poi_location-latitude', true ),
    				(float) get_post_meta( $object_id, 'poi_location-longitude', true )
    			);
    		}
    
    		return $check;
    	},
    	10,
    	3
    );
    
    /**
     * Output post meta 'lat-lng' with shortcode [lat-lng].
     */
    add_shortcode(
    	'lat-lng',
    	function(){
    		return get_post_meta( get_the_ID(), 'lat-lng', true );
    	}
    );

    Latitude always comes before longitude. Usage would be either shortcode [lat-lng] or PHP get_post_meta( get_the_ID(), 'lat-lng', true )

    Thread Starter Matt

    (@mybcn)

    Mind Blown! Thank you, good sir; that will work for me.

    //Matt

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How do I join 2 POD fields into 1’ is closed to new replies.