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

  1. vmodha
    Posted 4 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.

    $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?


  2. gastonius
    Posted 4 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
    Posted 4 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:

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Custom Field Template
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic