Giter Club home page Giter Club logo

Comments (19)

rilwis avatar rilwis commented on July 16, 2024

Maybe you want to check the field type taxonomy (in demo folder) with checkbox_list list styled.

from meta-box.

Thunderlab avatar Thunderlab commented on July 16, 2024

I've tried, but all I can get it's a single dropdown with all the parent and child taxonomies. =(

from meta-box.

rilwis avatar rilwis commented on July 16, 2024

Have you changed the options['type'] to checkbox_list?

from meta-box.

Thunderlab avatar Thunderlab commented on July 16, 2024

The problem is that I need my parent and child taxonomies spread in hierarchical (multiples) dropdowns, and not as a checkbox list. =(
When I choose a brand in the first dropdown, the second is loaded with the models, and when I pick a model, the third dropdown is loaded with the versions for that model.

Thanks!

from meta-box.

rilwis avatar rilwis commented on July 16, 2024

If you insist using dropdown select boxes, then you should work on custom JS code & ajax. IMHO, I think it's a common problem of ajax and JS. The meta box script at this moment doesn't support this feature.

But again, I'm asking you to try checkbox_list type. It has a same effect, but just with checkboxes.

from meta-box.

Thunderlab avatar Thunderlab commented on July 16, 2024

Thanks for your answer Rilwis. The checkbox_list it's not a option since I have about 100 different brands with thousands different models. The checkbox tree will be insanely huge in that situation.

I found this code that does the trick: https://gist.github.com/997350
Do you think that it's possible to implement it?

from meta-box.

funkatron82 avatar funkatron82 commented on July 16, 2024

I had a version of this working in the old version 3 of meta box. In it, it had a dropdown for just the parents. You selected a parent and another drop down for the children would appear and so on. Is that the type of functionality you want?

from meta-box.

Thunderlab avatar Thunderlab commented on July 16, 2024

Yes!!! It's what I want! With this version it's possible to have 3 levels of dropboxes? Parents -> children -> children of children? Thanks!!!

from meta-box.

 avatar commented on July 16, 2024

If I understand correct this is still included as checkbox_tree? (see the field-taxonomy.php)

from meta-box.

Thunderlab avatar Thunderlab commented on July 16, 2024

erodesign,

I don't need the checkbox tree, but some way to load parents and/or children toxonomies in dropdowns, so when a parent is selected in the first dropdown, the second dropdown would show only childrem related to that parent.

from meta-box.

Thunderlab avatar Thunderlab commented on July 16, 2024

I have this code working, but don't know how to integrate the generated dropdown with my metabox.
someone could help?

$brand_taxonomy = 'modelo';
$taxonomy_name = 'modelo';

add_action('add_meta_boxes', 'my_custom_metabox');
function my_custom_metabox() {
    add_meta_box('custom-taxonomy-dropdown','Brands','taxonomy_dropdowns_box','seminovo','side','high');
}
function taxonomy_dropdowns_box( $post ) {
    global $brand_taxonomy, $taxonomy_name;
    wp_nonce_field('custom-dropdown', 'dropdown-nonce');
    $terms = get_terms( $brand_taxonomy, 'hide_empty=0');
    if ( is_a( $terms, 'WP_Error' ) ) {
        $terms = array();
    }

    $object_terms = wp_get_object_terms( $post->ID, $brand_taxonomy, array('fields'=>'ids'));
    if ( is_a( $object_terms, 'WP_Error' ) ) {
        $object_terms = array();
    }
// you can move the below java script to admin_head
?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    jQuery('#custombrandoptions').change(function() {
    var custombrand = jQuery('#custombrandoptions').val();
    if (custombrand == '0') {
        jQuery('#custommodeloptions').html('');
        jQuery('#modelcontainer').css('display', 'none');
        } else {
        jQuery('#ctd-custom-taxonomy-terms-loading').css('display', 'inline');
        jQuery('#modelcontainer').css('display', 'none');
        var data = {
              'action':'get_brand_models',
              'custombrand':custombrand,
              'dropdown-nonce': jQuery('#dropdown-nonce').val()
              };
        jQuery.post(ajaxurl, data, function(response){
        jQuery('#custommodeloptions').html(response);
        jQuery('#ctd-custom-taxonomy-terms-loading').css('display', 'none');
        jQuery('#modelcontainer').css('display', 'inline');
               });
               }
               });
               });
</script>
<?php
echo "Marca:";
echo "<select id='custombrandoptions' name='custombrands[]'>";
echo "<option value='0'>None</option>";
foreach ($terms as $term ) {
            if ( $term->parent == 0) {
                if ( in_array($term->term_id, $object_terms) ) {
                    $parent_id = $term->term_id;
                    echo "<option value='{$term->term_id}' selected='selected'>{$term->name}</option>";
                  } else {
                    echo "<option value='{$term->term_id}'>{$term->name}</option>";
                }
            }
        }
        echo "</select>";
        echo "<div id='ctd-custom-taxonomy-terms-loading' style='display:none;'>Carregando...</div>";
        echo "<div id='modelcontainer'";
        if ( !isset( $parent_id)) echo " style='display: none;'";
        echo ">";
        echo "Modelo:";
        echo "<select id='custommodeloptions' name='custombrands[]'>";
        if ( isset( $parent_id)) {
            $models = get_terms( $brand_taxonomy, 'hide_empty=0&child_of='.$parent_id);
            foreach ( $models as $model ) {
                 if ( in_array($model->term_id, $object_terms) ) {
                    echo "<option value='{$model->term_id}' selected='selected'>{$model->name}</option>";
                } else {
                    echo "<option value='{$model->term_id}'>{$model->name}</option>";
                }
            }
        }
        echo "</select>";
        echo "</div>";
    }
    add_action('save_post','save_my_custom_taxonomy');
    function save_my_custom_taxonomy( $post_id ) {
        global $brand_taxonomy, $taxonomy_name;
        if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
            return;

        if ( !wp_verify_nonce($_POST['dropdown-nonce'], 'custom-dropdown'))
            return;

        $brands = array_map('intval', $_POST['custombrands']);
        wp_set_object_terms($post_id, $brands, $brand_taxonomy);
    }  
    add_action('wp_ajax_get_brand_models', 'get_brand_models');
    function get_brand_models() {
        global $brand_taxonomy, $taxonomy_name;
        check_ajax_referer('custom-dropdown', 'dropdown-nonce');
        if (isset($_POST['custombrand'])) {
            $models = get_terms( $brand_taxonomy, 'hide_empty=0&child_of='. $_POST['custombrand']);
            echo "<option value='0'>Select one</option>";
            foreach ($models as $model) {
                echo "<option value='{$model->term_id}'>{$model->name}</option>";
            }
        }
        die();
    }

from meta-box.

funkatron82 avatar funkatron82 commented on July 16, 2024

Pull request 99 has the new code that should do what you want. #99

from meta-box.

Thunderlab avatar Thunderlab commented on July 16, 2024

funkedgeek, thank you man!! =)
You make my day!!

from meta-box.

funkatron82 avatar funkatron82 commented on July 16, 2024

Let me know if it works okay

from meta-box.

Thunderlab avatar Thunderlab commented on July 16, 2024

works perfectly!!!! Thank you funkedgeek!
I just got a strange number upon my dropdown. See the screenshot: http://cl.ly/Exsl

from meta-box.

funkatron82 avatar funkatron82 commented on July 16, 2024

Yeah, sorry about that. Thats some debug code that I accidentally left in there. in the walk_select_tree function, remove line 182, the one that echoes$parent

from meta-box.

funkatron82 avatar funkatron82 commented on July 16, 2024

Fixed in the last commit

from meta-box.

Thunderlab avatar Thunderlab commented on July 16, 2024

Perfect as usual! =)

from meta-box.

BlockchainGuruClub avatar BlockchainGuruClub commented on July 16, 2024

Hi, it seems doen't work anymore ?...

from meta-box.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.