• Resolved ryansigg

    (@ryansigg)


    The filter function I have been using in 3.0.3 seems to be now broken in 3.1 beta 2.
    I know that filtering by multiple taxonomies is going to be part of 3.1, but I haven’t yet found anything relating to this new feature set. I also was not sure if the following method is now replaced by something because of the ability to do multiple queries.

    The following code, instead of successfully filtering the posts as before, somehow manages to even return other post types!

    If this turns out not to be related to a bug, I’ll be happy to repost in another forum instead.

    “Cruise” is the custom post type and “destination” is the custom taxonomy.

    add_action('restrict_manage_posts','restrict_cruises_by_destinations');
    
    function restrict_cruises_by_destinations() {
    	global $typenow;
    	global $wp_query;
    	if ($typenow=='cruise') {
    		$taxonomy = 'destination';
    		$destination_taxonomy = get_taxonomy($taxonomy);
    		wp_dropdown_categories(array(
    			'show_option_all' => __("Show All {$destination_taxonomy->label}"),
    			'taxonomy' => $taxonomy,
    			'name' => 'destination',
    			'orderby' => 'name',
    			'selected' => $wp_query->query['term'],
    			'hierarchical' => true,
    			'child_of' => 0,
    			'depth' => 3,
    			'show_count' => true,
    			'hide_empty' => true,
    		));
    	}
    }
    add_filter('parse_query','convert_destination_id_to_taxonomy_term_in_query');
    
    function convert_destination_id_to_taxonomy_term_in_query($query) {
    	global $pagenow;
    	$qv = &$query->query_vars;
    	if( $pagenow=='edit.php' && isset($qv['taxonomy']) && $qv['taxonomy']=='destination' && isset($qv['term']) && is_numeric($qv['term']) ) {
    		$term = get_term_by('id',$qv['term'],'destination');
    		$qv['term'] = $term->slug;
    	}
    }

    Any help would be much appreciated.

    Happy Holidays to all!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator Dion Hulse

    (@dd32)

    Meta Developer

    Try again with the RC, A change went in relating to the taxonomy/term query vars (which are being handled for back-compat purposes now)

    Thread Starter ryansigg

    (@ryansigg)

    Will do, Dion.
    Thanks, I’ll report back after I upgrade.

    Thread Starter ryansigg

    (@ryansigg)

    I installed the RC and I’m no longer getting weird query results. Now I’m just getting zero results when trying to restrict the posts by a taxonomy…

    Since I have 2 of these taxonomies I want to restrict posts by, perhaps I should wait until there is more documentation on multiple taxonomy queries before continuing…

    @ryansigg – Check out this post by somatic on a better/different way to do this that is wp3.1 RC compatible.

    https://wordpress.stackexchange.com/questions/578/adding-a-taxonomy-filter-to-admin-list-for-a-custom-post-type/3215#3215

    This adaptation is working for me in WP 3.2.1

    function restrict_your_post_type_by_your_taxonomy() {
    	global $typenow;
    	global $wp_query;
    	if ($typenow=='your_post_type') {
    		$taxonomy = 'your_taxonomy';
    		$your_taxonomy_tax = get_taxonomy($taxonomy);
    		wp_dropdown_categories(array(
    			'show_option_all' => __("Show All {$your_taxonomy_tax->label}"),
    			'taxonomy' => $taxonomy,
    			'name' => 'your_taxonomy',
    			'orderby' => 'name',
    			'selected' => $wp_query->query['your_taxonomy'],
    			'hierarchical' => true,
    			'child_of' => 0,
    			'depth' => 2,
    			'hide_empty' => false,
    		));
    	}
    }
    add_action('restrict_manage_posts','restrict_your_post_type_by_your_taxonomy');
    
    function convert_your_taxonomy_id_to_taxonomy_term_in_query($query) {
    	global $pagenow;
    	$qv = &$query->query_vars;
    	if( $pagenow=='edit.php' && isset($qv['your_taxonomy']) && is_numeric($qv['your_taxonomy']) ) {
    		$term = get_term_by('id',$qv['your_taxonomy'],'your_taxonomy');
    		$qv['your_taxonomy'] = $term->slug;
    	}
    }
    add_filter('parse_query','convert_your_taxonomy_id_to_taxonomy_term_in_query');

    You only have to change “your_post_type” and “your_taxonomy” to your needs.

    I have tweaked the second function a bit, as now wordpress passes the variable as your taxonomy name instead of a “term”.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    WP 3.2 and 3.1 are not ‘beta’ any more.

    If you continue to have issues with this, please open a post outside the alpha/beta forum ??

    Sorry, i ended here looking for a solution for this and didn’t realise this was the alpha/beta section.

    My fault

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom Taxonomy Filter not working in Admin edit.php 3.1(b2)’ is closed to new replies.