WordPress.org

Ready to get started?Download WordPress

Forums

Custom Field Template
[resolved] Providing a VALUE and OPTION in a SELECT item when using PHP CODE (3 posts)

  1. vmodha
    Member
    Posted 2 years ago #

    Hi, I'm using PHP CODE to generate a SELECT list. I'm passing a VALUE and OPTION but its only taking the OPTION.

    E.g.
    $values['valuex'] = 'Option X'

    Will give me a SELECT with:
    <option value="Option X">Option X</option>

    I'm building a form where the value is an ID, e.g. 5453545 and the visible option should be 'Option A'.

    Is this possible with your plugin?

    http://wordpress.org/extend/plugins/custom-field-template/

  2. gastonius
    Member
    Posted 2 years ago #

    Well, as it says, it's experimental at most… this code works with RADIO, after a quick look at the code I guess it works with SELECT but wont work with CHECKBOX.

    $valueLabel is the variable to use (same way: as array)

    $args = array('type' => 'post','child_of' => 0,'parent' => '', 'orderby' => 'name', 'order' => 'ASC', 'hide_empty'=> 0,'hierarchical'=> 1,'exclude'=> '','include'=> '','number'=> '','taxonomy'=> 'category','pad_counts'=> false );
    $categories = get_categories( $args );
    $outValues = Array();
    $outLabels = Array();
    foreach($categories as $category) {
    $outLabels[] = $category->name;
    $outValues[] = $category->slug;
    }
    $valueLabel = $outLabels;
    $values = $outValues;

    In theory, you should be able to rewrite any of these variables, and this is probably well documented in Author's web site, sadly to me: it's full of funny looking symbols :P

    $cftnum = $values = $valueLabels = $default = $hideKey = $label = $code = $class = $style = $before = $after = $selectLabel = $multipleButton = $onclick = $ondblclick = $onkeydown = $onkeypress = $onkeyup = $onmousedown = $onmouseup = $onmouseover = $onmouseout = $onmousemove = $onfocus = $onblur = $onchange = $onselect = '';

    Have fun,
    Gaston Gorosterrazu

  3. vmodha
    Member
    Posted 2 years ago #

    Thanks gastonius.

    Providing a set of two arrays, one for the 'keys' and one for the 'values' did the trick ;)

    You can translate the wpgogo site here:
    http://translate.google.co.uk/translate?hl=en&sl=ja&tl=en&u=http://wpgogo.com

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic