Answer the question
In order to leave comments, you need to log in
How to correctly put the path in wp_dropdown_categories?
Actually, I have already rummaged through everything I could, as far as my Google allowed me.
There is a taxonomy for the post type that determines the location of a person.
In the admin panel, these are areas and children of areas - settlements.
It looks something like this:
if ( is_tax() ) {
$queried_object = get_queried_object();
$this_category_id = $queried_object->term_id;
$selected = $queried_object->slug;
} else {
$this_category_id = '';
$selected = '';
}
//echo $selected;
$args = array(
'show_option_all' => esc_html__( 'Всі регiони або населенні пункти', 'youth-worker' ),
//'show_option_none' => __( 'Всі регiони', 'youth-worker' ),
'option_none_value' => '',
'orderby' => 'name',
'show_count' => 1,
'echo' => 0,
'hide_empty' => 0,
'hide_if_empty' => 1,
'hierarchical' => 1,
'value_field' => 'slug',
'depth' => 1,
'child_of' => $this_category_id,
'name' => 'volunteers-location',
'class' => 'volunteers-location',
'taxonomy' => 'volunteers-location',
//'selected' => $selected,
);
$dropdowncats = wp_dropdown_categories( $args );
$dropdown_replace = "<select$1 onchange='return this.form.submit()'>";
$dropdowncats = preg_replace( '#<select([^>]*)>#', $dropdown_replace, $dropdowncats );
?>
<?php if ( $dropdowncats ) : ?>
<form id="category-select" class="category-select" action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get">
<div class="search-category-wrapper">
<div class="select-wrapper">
<?php echo $dropdowncats; ?>
</div>
</div>
<noscript>
<input type="submit" value="<?php _e('Шукати', 'youth-worker') ?>">
</noscript>
</form>
<?php endif; ?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question