Snippet for US state abbreviations & Washington, DC
This topic contains 5 replies, has 3 voices, and was last updated by Naveen Giri 4 years, 8 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
March 19, 2020 at 2:37 pm #535741
Hello, I have implemented the Snippet below to change US state names to their abbreviations. There seems to be an issue with Washington, District of Columbia. Maybe you can help. Everything seems to be working properly with the states, but I noticed Washington, District of Columbia (DC) is displaying as “WA, DC” instead of “Washington, DC” as it should.
Since the US also has a state named Washington, I can see why that might be happening but is there something in the Snippet below that can limit the output to Region (state) only? In this case it seems to be replacing the city name as well as the state when it should only be replacing the state.
add_filter('geodir_custom_field_output_address','_my_short_state_geodir_cf_address',11,3); function _my_short_state_geodir_cf_address($html,$location,$cf){ // we add the >NAME< so we only replace the regions and not the region name in a street address. $state_long = array( ">Alabama<", ">Alaska<", ">Arizona<", ">Arkansas<", ">California<", ">Colorado<", ">Connecticut<", ">Delaware<", ">District of Columbia<", ">Florida<", ">Georgia<", ">Hawaii<", ">Idaho<", ">Illinois<", ">Indiana<", ">Iowa<", ">Kansas<", ">Kentucky<", ">Louisiana<", ">Maine<", ">Maryland<", ">Massachusetts<", ">Michigan<", ">Mississippi<", ">Missouri<", ">Montana<", ">Nebraska<", ">Nevada<", ">New Hampshire<", ">New Jersey<", ">New Mexico<", ">New York<", ">North Carolina<", ">North Dakota<", ">Ohio<", ">Oklahoma<", ">Oregon<", ">Pennsylvania<", ">Rhode Island<", ">South Carolina<", ">Tennessee<", ">Texas<", ">Utah<", ">Vermont<", ">Virginia<", ">Washington<", ">West Virginia<", ">Wisconsin<", ">Wyoming<", ); // we add the >NAME< so we only replace the regions and not the region name in a street address. $state_short = array( ">AL<", ">AK<", ">AZ<", ">AR<", ">CA<", ">CO<", ">CT<", ">DE<", ">DC<", ">FL<", ">GA<", ">HI<", ">ID<", ">IL<", ">IN<", ">IA<", ">KS<", ">KY<", ">LA<", ">MN<", ">MD<", ">MA<", ">MI<", ">MS<", ">MO<", ">MT<", ">NE<", ">NV<", ">NH<", ">NJ<", ">NM<", ">NY<", ">NC<", ">ND<", ">OH<", ">OK<", ">OR<", ">PA<", ">RI<", ">SC<", ">TN<", ">TX<", ">UT<", ">VT<", ">VA<", ">WA<", ">WV<", ">WI<", ">WY<", ); $html = str_replace($state_long,$state_short,$html); return $html; }
This snippet based on #post-372993
March 19, 2020 at 5:47 pm #535759Hi Foster,
Thanks for your post. I will forward this to a developer for further assistance. In the meantime, please share both WP and FTP access here in private reply for them to investigate.
March 26, 2020 at 6:35 am #536841Hi Foster,
could you please share the site details in the private reply.
Thanks
March 26, 2020 at 11:13 am #536877This reply has been marked as private.March 27, 2020 at 7:59 am #537033Hi Foster,
I have changed the snippet a bit to allow it only for states.
add_filter('geodir_custom_field_output_address','_my_short_state_geodir_cf_address',11,3); function _my_short_state_geodir_cf_address($html,$location,$cf){ // we add the >NAME< so we only replace the regions and not the region name in a street address. $state_long = array( 'addressRegion">Alabama<', 'addressRegion">Alaska<', 'addressRegion">Philadelphia<', 'addressRegion">Arizona<', 'addressRegion">Arkansas<', 'addressRegion">California<', 'addressRegion">Colorado<', 'addressRegion">Connecticut<', 'addressRegion">Delaware<', 'addressRegion">District of Columbia<', 'addressRegion">Florida<', 'addressRegion">Georgia<', 'addressRegion">Hawaii<', 'addressRegion">Idaho<', 'addressRegion">Illinois<', 'addressRegion">Indiana<', 'addressRegion">Iowa<', 'addressRegion">Kansas<', 'addressRegion">Kentucky<', 'addressRegion">Louisiana<', 'addressRegion">Maine<', 'addressRegion">Maryland<', 'addressRegion">Massachusetts<', 'addressRegion">Michigan<', 'addressRegion">Mississippi<', 'addressRegion">Missouri<', 'addressRegion">Montana<', 'addressRegion">Nebraska<', 'addressRegion">Nevada<', 'addressRegion">New Hampshire<', 'addressRegion">New Jersey<', 'addressRegion">New Mexico<', 'addressRegion">New York<', 'addressRegion">North Carolina<', 'addressRegion">North Dakota<', 'addressRegion">Ohio<', 'addressRegion">Oklahoma<', 'addressRegion">Oregon<', 'addressRegion">Pennsylvania<', 'addressRegion">Rhode Island<', 'addressRegion">South Carolina<', 'addressRegion">Tennessee<', 'addressRegion">Texas<', 'addressRegion">Utah<', 'addressRegion">Vermont<', 'addressRegion">Virginia<', 'addressRegion">Washington<', 'addressRegion">West Virginia<', 'addressRegion">Wisconsin<', 'addressRegion">Wyoming<', ); // we add the >NAME< so we only replace the regions and not the region name in a street address. $state_short = array( 'addressRegion">AL<', 'addressRegion">AK<', 'addressRegion">pd<', 'addressRegion">AZ<', 'addressRegion">AR<', 'addressRegion">CA<', 'addressRegion">CO<', 'addressRegion">CT<', 'addressRegion">DE<', 'addressRegion">DC<', 'addressRegion">FL<', 'addressRegion">GA<', 'addressRegion">HI<', 'addressRegion">ID<', 'addressRegion">IL<', 'addressRegion">IN<', 'addressRegion">IA<', 'addressRegion">KS<', 'addressRegion">KY<', 'addressRegion">LA<', 'addressRegion">MN<', 'addressRegion">MD<', 'addressRegion">MA<', 'addressRegion">MI<', 'addressRegion">MS<', 'addressRegion">MO<', 'addressRegion">MT<', 'addressRegion">NE<', 'addressRegion">NV<', 'addressRegion">NH<', 'addressRegion">NJ<', 'addressRegion">NM<', 'addressRegion">NY<', 'addressRegion">NC<', 'addressRegion">ND<', 'addressRegion">OH<', 'addressRegion">OK<', 'addressRegion">OR<', 'addressRegion">PA<', 'addressRegion">RI<', 'addressRegion">SC<', 'addressRegion">TN<', 'addressRegion">TX<', 'addressRegion">UT<', 'addressRegion">VT<', 'addressRegion">VA<', 'addressRegion">WA<', 'addressRegion">WV<', 'addressRegion">WI<', 'addressRegion">WY<', ); $html = str_replace($state_long,$state_short,$html); return $html; }
Please have a look now.
Regards
NaveenApril 7, 2020 at 7:32 am #538844Hi Foster,
I hope it has been fixed for you. I will close this task here.
Let me know if you have any further concerns.
Thanks
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket