• I have tried a couple solutions to get a dropdown of custom taxonomy terms that link to entries with the selected term.

    I have tried a number of solutions I found in the codex and forums, shown below, and keep getting 404s as the results pages when the link resolves.

    <form id="category-select" class="category-select" action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get">
    
    		<?php
    		$args = array(
                            'taxonomy' => 'location',
                            'show_option_none' => __( 'Select category' ),
    			'show_count'       => 1,
    			'orderby'          => 'name',
    			'echo'             => 0,
    		);
    		?>
    
    		<?php $select  = wp_dropdown_categories( $args ); ?>
    		<?php $replace = "<select$1 onchange='return this.form.submit()'>"; ?>
    		<?php $select  = preg_replace( '#<select([^>]*)>#', $replace, $select ); ?>
    
    		<?php echo $select; ?>
    
    		<noscript>
    			<input type="submit" value="View" />
    		</noscript>
    
    	</form>
    <?php wp_dropdown_categories('taxonomy=location&show_option_none=Select location'); ?>
    
    <script type="text/javascript"><!--
        var dropdown = document.getElementById("cat");
        function onCatChange() {
    		if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
    			location.href = "<?php echo get_option('home');
    ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
    		}
        }
        dropdown.onchange = onCatChange;
    --></script>
    <form id="category-select" class="category-select" action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get">
        <?php wp_dropdown_categories( 'taxonomy=location&show_option_none=Select location' ); ?>
        <input type="submit" name="submit" value="view" />
    </form>

    I deactivate all plugins except the custom plugin with the CPT and taxonomies. I set permalinks to plain and back to pretty. I tested with the Twenty Fifteen theme. All had the same result, 404.

    How can I fix this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Sadly wp_dropdown_categories seems broken when it comes to the permalinks.

    I’m using this working version from here.

    <form action="<?php bloginfo('url'); ?>/" method="get">
    
    <?php
    $term_id = 279;
    $taxonomy_name = 'categories';
    $termchildren = get_term_children( $term_id, $taxonomy_name );
    $children = array();
    foreach ($termchildren as $child) {
      $term = get_term_by( 'id', $child, $taxonomy_name );
      $children[$term->name] = $term;
    }
    ksort($children);
    echo '<select name="' . $taxonomy_name . '" onchange="this.form.submit()">';
    echo '<option selected>Branding...</option>';
    foreach ( $children as $child ) {
      $term = get_term_by( 'id', $child->term_id, $taxonomy_name );
      echo '<option value="'. $term->slug .'">' . $term->name . '</a></option>';
    }
    echo '</select>';
    ?>
    <noscript><div><input type="submit" value="View" /></div></noscript>
    
    </form>

    Sadly wp_dropdown_catetories seems broken when it comes to permalinks.

    I am using a different method from here.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_dropdown_categories with custom taxo goes to 404’ is closed to new replies.