I'm using wordpress, and for the website that I'm working on, I've set up a custom post type for listing each of their services and details.
On their custom contact form, I'm querying the custom post type to get the titles for each post into an option list so a user can select which service they're interested in.
Part of the form logic when the form is submitted checks to see that all of the required fields are filled in, and if not, it gives an alert and asks the user to fill in the needed info.
I have a piece of php code in each input to echo the posted data back into the form so that it is not lost, and I'm trying to do the same for the option drop down but I'm running into a really frustrating issue:
Any wordpress post title with and ampersand in it is having the ampersand replaced by a char code of &, which is fine, it shows as an & in my browser, but after it's submitted it turns into an & in the post data.
When I try to compare each post title to the submitted selection, the if statement never finds a match because the & and & don't match up.
I've tried using htmlspecialchars_decode() on the titles from wordpress, but this doesn't decode the & back into and &.
Does anyone know of a function to accomplish this and decode any weird char encoding that might pop up?
Here's my while loop where this takes place.
while ($custom_post_type->have_posts()) : $custom_post_type->the_post();
//set selected if submission is bouncing back
if($_POST['ftype'] == get_the_title())
{
$the_selected = ' selected="selected" ';
}
else
{
$the_selected = '';
}
?>
<option value="<?php echo get_the_title(); ?>" <?php echo $the_selected; ?>><?php echo get_the_title(); ?></option>
<?php
endwhile;
html_entity_decode
should work.There's a plugin for WordPress that can help you:
https://wordpress.org/plugins/wp-no-format/