Answers.Body: <p>It turns out that the "Search Primary Details Only" setting causes this problem (found under Administer-> Customize Data and Screens-> Search Preferences). It seems that if this setting is off, the listings and export will default to the address which was created earlier.</p>
  
  <p>See here for details: 
  <a href="https://civicrm.stackexchange.com/questions/31457/contact-search-results-address-type">Contact Search Results Address Type</a></p>
  
  <p>This is a weird behaviour in the listings, but for the exports seems like a bug as selecting primary address types in an export does not return primary addresses.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-05T19:02:01.500Z
Answers.LastActivityDate: 2019-09-05T19:02:01.500Z
Answers.UserDisplayName: Lars SG
Answers.Body: <p>The export issue is actually a confirmed bug, see <a href="https://lab.civicrm.org/dev/core/issues/464" rel="nofollow noreferrer">https://lab.civicrm.org/dev/core/issues/464</a> 
  I have had moderate success using hook_civicrm_export in a custom extension for a client where email location type is really important to their workflow.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-05T19:50:25.703Z
Answers.LastActivityDate: 2019-09-05T19:50:25.703Z
Answers.UserDisplayName: m robinson
Body: <p>I'm exporting contacts with both home and billing addresses, where the home address is set as primary. Even though I've selected primary as the address type for all address fields in the export fields selection, some of the fields in the export are actually the billing address (which is definitely not set as the primary address).</p>
  
  <p>Has anyone else run into this or does anyone know why this might be happening?</p>
  
  <p>It's hard to tell exactly how many contacts this is happening to, but it does seem to be a significant number. I have not been able to replicate the issue on the demo site.</p>
  
  <p>5.7.6 on Drupal.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-09-05T13:33:41.720Z
Comments.Text: I'd start by looking at the errors and seeing if there's a pattern.
Comments.UserDisplayName: Alan Dixon
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-09-05T15:50:32.803Z
Comments.Text: So far, all the errors I can find involve contacts with a non-primary billing address with no province/state.
  Also, I'm seeing that the displayed address in the group listing is also showing the non-primary billing address.
  Adding the province/state does not fix the problem.
Comments.UserDisplayName: Lars SG
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-09-05T17:11:36.933Z
Comments.Text: Have found some counter examples, there are contact with missing province/state in the non-primary billing address that export correctly and there are contact the export incorrectly that have the correct province/state in the billing address. Still seems like missing province/state is found along with this error most of the time.
Comments.UserDisplayName: Lars SG
Tags: <export><addresses>
Title: Exporting primary addresses exports non-primary addresses for some contacts
ThreadText: # Exporting primary addresses exports non-primary addresses for some contacts
  
  (Asked by: username_0 on 2019-09-05)
  
  I'm exporting contacts with both home and billing addresses, where the home address is set as primary. Even though I've selected primary as the address type for all address fields in the export fields selection, some of the fields in the export are actually the billing address (which is definitely not set as the primary address).
  
  Has anyone else run into this or does anyone know why this might be happening?
  
  It's hard to tell exactly how many contacts this is happening to, but it does seem to be a significant number. I have not been able to replicate the issue on the demo site.
  
  5.7.6 on Drupal.
  
  **Tags:** export, addresses
  
  > **Comments:**
  > **username_1**: I'd start by looking at the errors and seeing if there's a pattern.  
  > **username_0**: So far, all the errors I can find involve contacts with a non-primary billing address with no province/state. Also, I'm seeing that the displayed address in the group listing is also showing the non-primary billing address. Adding the province/state does not fix the problem.  
  > **username_0**: Have found some counter examples, there are contact with missing province/state in the non-primary billing address that export correctly and there are contact the export incorrectly that have the correct province/state in the billing address. Still seems like missing province/state is found along with this error most of the time.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2019-09-05. Score: 3
  
  It turns out that the "Search Primary Details Only" setting causes this problem (found under Administer-> Customize Data and Screens-> Search Preferences). It seems that if this setting is off, the listings and export will default to the address which was created earlier.
  
  See here for details:
  [Contact Search Results Address Type](https://civicrm.stackexchange.com/questions/31457/contact-search-results-address-type)
  
  This is a weird behaviour in the listings, but for the exports seems like a bug as selecting primary address types in an export does not return primary addresses.
  
  
  ---
  
  ### Answer by username_2 on 2019-09-05. Score: 1
  
  The export issue is actually a confirmed bug, see <https://lab.civicrm.org/dev/core/issues/464>
  I have had moderate success using hook\_civicrm\_export in a custom extension for a client where email location type is really important to their workflow.
  
  
  ---
  
  