Comments (19)
Maybe you want to check the field type taxonomy
(in demo
folder) with checkbox_list
list styled.
from meta-box.
I've tried, but all I can get it's a single dropdown with all the parent and child taxonomies. =(
from meta-box.
Have you changed the options['type']
to checkbox_list?
from meta-box.
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.
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.
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.
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.
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.
If I understand correct this is still included as checkbox_tree
? (see the field-taxonomy.php
)
from meta-box.
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.
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.
Pull request 99 has the new code that should do what you want. #99
from meta-box.
funkedgeek, thank you man!! =)
You make my day!!
from meta-box.
Let me know if it works okay
from meta-box.
works perfectly!!!! Thank you funkedgeek!
I just got a strange number upon my dropdown. See the screenshot: http://cl.ly/Exsl
from meta-box.
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.
Fixed in the last commit
from meta-box.
Perfect as usual! =)
from meta-box.
Hi, it seems doen't work anymore ?...
from meta-box.
Related Issues (20)
- How to Display MB Views Shortcodes Content after Product Description HOT 1
- Placeholder for "Select an user" HOT 1
- not published
- Geolocation + OSM
- Zion Builder Support HOT 1
- Custom Fields Group - rwmb_meta for single image no returning array HOT 1
- Contact form at metabox.io/contact is returning an error HOT 1
- Translation not showing HOT 2
- Undefined array key HOT 2
- Latest version Meta Box (5.6.9) kills MB Custom Table
- URGENT: Latest version Meta Box (5.6.10) kills MB User Meta and related plugins HOT 2
- Uncaught Error: Class 'RWMB_Update_Option' not found when adding new post type HOT 1
- Master branch here on GitHub is not current with version on Wordpress Repo HOT 2
- Switch labels are off HOT 2
- Usage of Select Advanced for taxonomies in admin HOT 1
- Require image orientation on image_advanced field upload HOT 1
- subtitle custom field HOT 2
- Media Library Never Loads HOT 3
- Fatal Error in Taxonomy Field on Frontend Form Following MB Update to Version 5.7.2
- Meta Box interferes with my website's Logo when activated HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meta-box.