WordPress.org

Ready to get started?Download WordPress

Forums

WordPress 3 ampersand in category name (5 posts)

  1. slee
    Member
    Posted 3 years ago #

    I am creating an options page for a site I am building and I have hit a problem that I have not noticed before and that is when selecting a category that has an ampersand (&) in the category name it will not show the correctly selected category when going back to the options page.

    Is there a way around this?
    I have tried using & but i guess as it contains the & it still errors.

    This is for an options page, so I am using:

    $categories_list = get_categories('hide_empty=0');
    
    $categories = array();
    foreach ($categories_list as $catlist) {
    	$categories[$catlist->cat_ID] = $catlist->cat_name;
    }
    array_unshift($categories, "Choose a category");

    then

    case 'select':
    ?>
    
    <div class="tfh_input tfh_select">
    	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
    
    <select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
    <?php foreach ($value['options'] as $option) { ?>
    		<option <?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?>
    </select>
    <small><?php echo $value['desc']; ?></small>
    	<div class="clearfix"></div>
    </div>
    <?php
    break;

    which i think is pretty standard?

    Any ideas on how i can around this so it still works with the ampersand in the category name or is this a bug?

  2. Erik Ford
    Member
    Posted 3 years ago #

    I would be interested in knowing what can be done to troubleshoot this issue. We are running into the same problem with our Theme Options panel and the custom query in the theme.

    If the category name has an ampersand, the query breaks. I am assuming that this is because it is interpreting the ampersand as code. So, how do we get the data from the Theme Options and convert it into something that won't break the query?

  3. IIRC, WordPress escapes the code to & which ... is for sanitization/security reasons.

    Looks like http://core.trac.wordpress.org/ticket/14584 exists for the general problem.

  4. Erik Ford
    Member
    Posted 3 years ago #

    Thanks. I figured it was something integral to the application itself.

  5. Yeah, I have the same problems with other web-apps and the & sign

    My example was supposed to be & amp ; - heh.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.