Can someone help me with this function code form?

Hi all!

I need advice on code, I have tested and works correctly the first show, but I hate the second function, add the two functions have if someone can advise me any recommendations would be helpful, and I'm stuck.

function Select($tax){
$terms = get_terms($tax);
$x = '<select name="'. $tax .'">';
$x .= '<option value="">Select '. ucfirst($tax) .'</option>';
foreach ($terms as $term) {
$x .= '<option value="' . $term->slug . '">' . $term->name . '</option>';
}
$x .= '</select>';
return $x;
}

This function performs correctly, when I add taxonomy fields automatically embedded in me the taxonomy selection box of the browser, but I have no clear concept for the same with checkbox, I put the incomplete function.

function checkbox($tax){
$terms = get_terms($tax);
$x = '<input type="checkbox" name="'. $tax .'">';
$x .= '<option value="">Select '. ucfirst($tax) .'</option>';
foreach ($terms as $term) {
$x .= '<option value="' . $term->slug . '">' . $term->name . '</option>';
}
$x .= '</select>';
return $x;

Thanks in advance greetings.

Paches.

  • Paches
    • WPMU DEV Initiate

    Hello rpeterson,

    Thanks for the help, excuse the not have expressed myself well my English is not very good.

    Anyway, I've done a search, which can sever different taxonomies, to define the search publish particular type.

    I created a form, which is composed of "select" and "checkbox" function:

    function Select ($ tax) {
    $ terms = get_terms ($ tax);
    $ x = '<select name="'. $tax .'">';
    $ x. = '<option value=""> Select'. ucfirst ($ tax). '</ option>';
    foreach ($ terms as $ term) {
    $ x. = '<option value="'. $term-> slug.' "> '. $ term-> name. '</ option>';
    }
    $ x. = '</ select>';
    return $ x;
    }

    I works perfectly, as I add terms to a taxonomy automatically added to select the finder as new selection option for search.

    The problem is not how to do the same function for the checkbox, I tried but I can not.

    function checkbox ($ tax) {
    $ terms = get_terms ($ tax);
    $ x = '<input type="checkbox" name="'. $tax .'">';
    $ x. = '<option value=""> Select'. ucfirst ($ tax). '</ option>';
        foreach ($ terms as $ term) {
    $ x. = '<option value="'. $term-> slug.' "> '. $ term-> name. '</ option>';
    }
    $ x. = '</ select>';
    return $ x;
    }

    What I need is to do the same function as the select but with chexkbox, hope I did not messed over.

    Thank you very much for the contribution.

    Paches.

  • rpeterson
    • Flash Drive

    @Paches

    I am going to take a shot at some code here, hoping it does what you need. If not, please send some screenshots of what your seeing / doing to help put it into context.

    function checkbox ($tax) {
        $terms = get_terms ($tax);
        $x = "<label><input type="hidden" name='{$tax}' value='0'>";
        $x .= "<input type="checkbox" name='{$tax}' value='{$term->slug}'>";
        $x .= "{$term-> name} </label>";
        return $x;
    }

    Maybe I am way off on what you want it to do, I apologize, I am doing my best to interpret what you're trying to communicate :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.