Skip Navigation

[Resolved] Exclude and re-order specific address information in view

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to format address field in specific format

Solution:
You should have to split your string using comma and then build your required address string in specific format using the custom shortcode where you should pass the address field value as argument to shortcode.

You can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/exclude-and-re-order-specific-address-information-in-view/#post-622411

Relevant Documentation:

This support ticket is created 6 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by Bob 6 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#620036

Bob

I'm trying to make a listing of resellers including their addresses. In my output the Country is always listed even though this is not relevant.

My questions:
• How to exclude the Country from the view results.
• Also I would like to be able to apply breaks in the output.

Current (fictional) output:
Mickey Mousestraat 15, Almere, Nederland

Preferred output:
Mickey Mousestraat 15
Almere

Thanks in advance,
Bob

#620080

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - this depends what field type you used to store your address value and how it's stored inside the database.

There is no way to exclude the country name from your address until we process your string in such way to delete the address value and format it according to your need.

You should have to split your string using comma and then build your required string. But I can guide you more once I can check your setup how the string is stored and where exactly you want to display it is said format.

Could you please send me problem URL where you want to display the address.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#622073

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've added following custom shortcode to your current theme's functions.php file:

function func_display_address( $atts,$content) {
	 $a = shortcode_atts( array(
        'field' => '',
       ), $atts );
	   
	   $content = wpv_do_shortcode($content);
	   $content = explode(",",$content);
	  
	   
	   $val = '';
	   $count = count($content)-1;
	   
	   for($i=0;$i<$count;$i++){
			$val = $val.$content[$i]." <br/> ";
		}
	   return $val;
	   
    
}
add_shortcode( 'display_address', 'func_display_address' );

And I've called the shortcode as given under:

<td> [display_address][types field='adres-reseller'][/types][/display_address]</td>

And I can see now the Address is displayed as expected:
=> hidden link

#622096

Bob

Hey Minesh,

That's great! Thanks 🙂
When I sent you the login details, I also added some extra information, which I don't see in our conversation... The client I'm building this site for will be expanding abroad shortly, so actually the country name will be relevant after all 🙂

Whats changes need to be made to make it look like this:
Mickey Mousestraat 15
Almere, Nederland

Thanks again!

#622411

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - I've modified the code as requested and added to your current theme's functions.php file:

function func_display_address( $atts,$content) {
	 $a = shortcode_atts( array(
        'field' => '',
       ), $atts );
	   
	   $content = wpv_do_shortcode($content);
	   $content = explode(",",$content);
	  
	   
	   $val = '';
	   $count = count($content);
	   
	   for($i=0;$i<$count;$i++){
 		  if($i%2===0){
			$val = $val.$content[$i]."<br/> ";
		  }else{
			  $val = $val.$content[$i].",";
		  }
		  
		}
	   return $val;
	   
    
}
add_shortcode( 'display_address', 'func_display_address' );

And I can see now the Address is displayed as expected:
=> hidden link

Could you please confirm 🙂

#622906

Bob

Thanks Minesh, you work wonders 🙂