Jump to content

How do I fix php custom field link generation for cities with multiple words?


Go to solution Solved by hansford,

Recommended Posts

I'm using php to generate duplicate pages with established custom fields that change for each page. So if the city/state fields were Sacramento, CA- then it would generate the url to be-  www.mysite.com/my-subject-sacramento-ca. However, some pages have cities that are multiple words, like San Diego. So, when that link is generated, it links to www.mysite.com/my-subject-san diego-ca. It puts a space instead of a dash after Cape. Anyone know how to add to the statement and make it so that for cities with multiple words in the name, it adds a "-" in between in the url, not just a space?? Code below. Thanks!

 

<li><a href="<?php bloginfo ('url') ; ?>/my-subject-<?php echo $citylower; ?>-<?php echo $statelower; ?>">My Subject <?php the_field('city_town'); ?>, <?php the_field('state_abr'); ?></a></li>

Edited by sandydandy89
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.