Home Forums Plugin Support WP User Frontend Pro Taxonomy Passing Along Additional Data

This topic is: resolved

This topic contains 4 replies, has 2 voices, and was last updated by  Tareq Hasan 6 years, 1 month ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #3504

    tripod0502
    Participant
    Post count: 8

    Hey Guys! I've run into a problem I need a little help

    The template I am using implements a custom post type as a “directory” In this directory, the taxonomy is related to geographic locations. Atlanta, Georgia – Knoxville, Tennessee – etc.

    I am looking for a way to pass along additional data (GPS coordinates) related to the locations listed in the taxonomy to populate a (preferably hidden) field.

    So, as a user selects “Atlanta, Georgia” from the taxonomy drop-down…it in turn would reflect “XXX.XXXX” in a latitude field and “XXX.XXXX” in a longitude field.

    I know that it's going to take some PHP wizardry in the functions file. The coordinates could even be coded in the file itself- as the locations will not change any time soon.

    Any pointers? Thanks in advance!

    #3512

    Tareq Hasan
    Keymaster
    Post count: 2831

    I am not sure how your theme is saving that info for those taxonomy, cause WP doesn't have any method to save taxonomy meta. Only can be possible with some other plugin, like Taxonomy Metadata.
    Here's an example code to show how you can save the lat/long.

    [php]
    function wpufe_tax_meta( $post_id ) {
    // I assume the map meta key is "location"
    if ( isset( $_POST[‘location'] ) ) {
    list( $latitude, $longitude ) = explode( ‘,', $_POST[‘location'] );

    // save latitude and longitude
    }
    }

    add_action( ‘wpuf_add_post_after_insert', ‘wpufe_tax_meta' );
    add_action( ‘wpuf_edit_post_after_update', ‘wpufe_tax_meta' );
    [/php]

    #3515

    tripod0502
    Participant
    Post count: 8

    Tareq,

    Thanks for the fast response! I don't know how you do it…but, you are the man. You may remember dealing with another user in regards to the AIT Directory theme…where you gave us the code below…

    [php]
    function wpufe_ait_integration( $post_id ) {

    $def_lat = $def_long = 0;

    if ( isset( $_POST[‘location'] ) ) {
    list( $def_lat, $def_long ) = explode( ‘,', $_POST[‘location'] );
    }

    $ait_dir_item = array (
    ‘address' => isset( $_POST[‘address'] ) ? $_POST[‘address'] : ”,
    ‘gpsLatitude' => $def_lat,
    ‘gpsLongitude' => $def_long,
    ‘streetViewLatitude' => ”,
    ‘streetViewLongitude' => ”,
    ‘streetViewHeading' => ‘0',
    ‘streetViewPitch' => ‘0',
    ‘streetViewZoom' => ‘0',
    ‘telephone' => isset( $_POST[‘telephone'] ) ? $_POST[‘telephone'] : ”,
    'email' => isset( $_POST['email'] ) ? $_POST['email'] : ”,
    ‘web' => isset( $_POST[‘web'] ) ? $_POST[‘web'] : ”,
    ‘hoursMonday' => isset( $_POST[‘hours_monday'] ) ? $_POST[‘hours_monday'] : ”,
    ‘hoursTuesday' => isset( $_POST[‘hours_tuesday'] ) ? $_POST[‘hours_tuesday'] : ”,
    ‘hoursWednesday' => isset( $_POST[‘hours_wednesday'] ) ? $_POST[‘hours_wednesday'] : ”,
    ‘hoursThursday' => isset( $_POST[‘hoursThursday'] ) ? $_POST[‘hoursThursday'] : ”,
    ‘hoursFriday' => isset( $_POST[‘hoursFriday'] ) ? $_POST[‘hoursFriday'] : ”,
    ‘hoursSaturday' => isset( $_POST[‘hoursSaturday'] ) ? $_POST[‘hoursSaturday'] : ”,
    ‘hoursSunday' => isset( $_POST[‘hoursSunday'] ) ? $_POST[‘hoursSunday'] : ”,
    ‘alternativeContent' => isset( $_POST[‘alternativeContent'] ) ? $_POST[‘alternativeContent'] : ”,
    );

    update_post_meta( $post_id, ‘_ait-dir-item', $ait_dir_item );
    }

    add_action( ‘wpuf_add_post_after_insert', ‘wpufe_ait_integration' );
    add_action( ‘wpuf_edit_post_after_update', ‘wpufe_ait_integration' );

    [/php]

    But, instead of geocoding the address given in the form, I'm looking to use the latitude and longitude from the meta of the “location” taxonomy…so that users can only choose specified locations, which will be show themselves on the theme's integrated Google map.

    #3516

    tripod0502
    Participant
    Post count: 8

    I hate to sound ignorant…but, would “Ultimate Taxonomy Manager” (http://taxonomymanager.wordpress.com/) work the same way as Taxonomy Metadata?

    I've used it to create two custom taxonomy fields named “gpslatitude” and “gpslongitude”

    #3517

    Tareq Hasan
    Keymaster
    Post count: 2831

    I can't actually say if it will work or not, it should work. Somehow the taxonomy is saving extra data into database right? So you've to save it too and I gave you the placeholder area in the code where you need to save that data to the right place ๐Ÿ˜‰

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

The topic ‘Taxonomy Passing Along Additional Data’ is closed to new replies.