Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

So I'm at my wit's end here. I've done this before plenty of times, but I think I have stared at this so much I am missing something.

  • I basically have a custom post called locations. That custom post has a few fields which include address, and latitude and longitude.

    • that lat/long are geocoded so they get automatically populated after the user enters in the address (so they can later be dumped into a map):

    the_field('latitude'); ?> the_name(); ?>" value="the_value(); ?>"/>

    the_field('longitude'); ?> the_name(); ?>" value="the_value(); ?>"/>

  • The second part of this is the people custom field that has a select box that lets the user select the title of each of those locations:

    the_name(); ?>"> Select Location ID; ?>" the_select_state($office->ID)?>>post_title; ?>

The final piece that I am having issues with is tying them together. I have a query displaying the information for the people:

Based on the region selection in the people custom post, I want to display the last and long fields in the locations post. I've done something similar before without any issues, but this time around it's not cooperating. I've tried different variations, but here is where I am right now:

<?php 
        $people = get_posts(array(
        'post_type' => 'person',
        'nopaging' => 'true',
        'order' => 'ASC'
        )); 

    foreach ($people as $person) :
        $office = 'office';
        $office_id = get_post_meta($person->ID, 'person_location', TRUE);
    ?>

   <?php get_post_meta($office_id, "latitude", true); ?>', '<?php echo get_the_title($office_id); ?>

I've tried different things including creating a custom query with no avail:

function get_latLong($office_id) {
    global $wpdb;


    $mylink = $wpdb->get_row("SELECT * FROM $wpdb->location WHERE id ='" . $office_id . "'");
    echo $mylink->latitude;

}

Any insight would be greatly appreciated! Thanks

share|improve this question
    
So just to be clear, you want the user to pick a location in a drop down, then pick a person at that location in a second drop down, but the second drop down must only contain people in that location and not a full list of people? –  Tom J Nowell Feb 3 '12 at 17:52
    
So there are two custom posts. The one for locations where you enter the location name, address, and the lat/long are geocoded automatically into invisible input boxes. The custom posts for people has a select box that's pulling the title/value(id in this case) of the locations. When running a loop for the people custom post in my template I'd like to spit out the latitude and longitude input boxes based on the select option selected in the people post. –  tedi Feb 3 '12 at 18:00
    
You're questions written a little confusingly. –  Tom J Nowell Feb 3 '12 at 18:01
    
So you have a person post type, and an office/location post type. Each person has an office, and the ID of the office is stored in meta, right? –  Tom J Nowell Feb 3 '12 at 18:02
    
You want to get the longitude and latitude of the office a person resides at? –  Tom J Nowell Feb 3 '12 at 18:02

2 Answers 2

Given the post types person and location, this will print out the latitude and office of every person:

$q = new WP_query(array( 'post_type'=> 'person'));
if($q->have_posts()){
    while($q->have_posts()){
        $q->the_post();
        $location_id = get_post_meta($post->ID, 'person_location', true);
        if(!empty($location_id)){
            echo '<p>'.get_the_title($location_id).' is at latitude: "'.get_post_meta($location_id, "latitude", true).'"';
        } else {
            // something went wrong here
        }
    }
}
wp_reset_postdata();

Put an error debug call in the else statement, and if the latitude isn't set you'll get a latitude of "", which should indicate where to bughunt

share|improve this answer
    
Thanks Tom! However I'm afraid that doesn't work. That's part 1 where it displays the selection from the person custom post. The next step which is where I'm stuck in, is to compare that to the locations custom post, to spit out the latitude and longitude of that location based on the person post selection. –  tedi Feb 3 '12 at 18:22
    
Got it. So this works: $office_id = get_post_meta($leader->ID, 'leader_location', TRUE); ?> ['<?php echo get_post_meta($office_id, "latitude", true); ?>,<?php echo get_post_meta($office_id, "longitude", true); ?> –  tedi Feb 3 '12 at 18:31
    
It would appear you're missing vital information about your UI design and how you want it to work. E.g. do you have a combobox of people that gets submitted as a form? Are you expecting it to do it all on the one page via javascript? –  Tom J Nowell Feb 4 '12 at 15:09
    
Or are you wanting to show it on an individual person post once clicked through? –  Tom J Nowell Feb 4 '12 at 15:10
    
What I'm saying is you've described your solution and that it's broken without properly defining in solid terms the original problem –  Tom J Nowell Feb 4 '12 at 15:10

Could it be that:

<?php get_post_meta($office_id, "latitude", true); ?>

Should be

<?php echo get_post_meta($office_id, "latitude", true); ?>

AKA a missing echo statement?

share|improve this answer
    
Tried that without much luck. –  tedi Feb 3 '12 at 18:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.