Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This question relates to a solution found here from user somatic and mikeSchinkel

I am testing somatic's solution, and it loads and populates the dropdown with no issues, but When you click filter, it does not filter anything. I am on WP version 3.0.4.

My custom post type = "listings" my custom taxonomy = "Locations"

the code:

add_action( 'restrict_manage_posts', 'my_restrict_manage_posts' );
function my_restrict_manage_posts() {

    // only display these taxonomy filters on desired custom post_type listings
    global $typenow;
    if ($typenow == 'listings') {

        // create an array of taxonomy slugs you want to filter by - if you want to retrieve all taxonomies, could use get_taxonomies() to build the list
        $filters = array('Locations');

        foreach ($filters as $tax_slug) {
            // retrieve the taxonomy object
            $tax_obj = get_taxonomy($tax_slug);
            $tax_name = $tax_obj->labels->name;
            // retrieve array of term objects per taxonomy
            $terms = get_terms($tax_slug);

            // output html for taxonomy dropdown filter
            echo "<select name='$tax_slug' id='$tax_slug' class='postform'>";
            echo "<option value=''>Show All $tax_name</option>";
            foreach ($terms as $term) {
                // output each select option line, check against the last $_GET to show the current option selected
                echo '<option value='. $term->slug, $_GET[$tax_slug] == $term->slug ? ' selected="selected"' : '','>' . $term->name .' (' . $term->count .')</option>';
            }
            echo "</select>";
        }
    }
}

Am I missing something in there to make the filter work? I am organizing my column's with the following code, not what was in step 3 and 4. (not sure if this is the issue?)

add_action("manage_posts_custom_column",  "listing_custom_columns");
add_filter("manage_edit-listings_columns", "listing_edit_columns");

function listing_edit_columns($columns){
  $columns = array(
    "cb" => "<input type=\"checkbox\" />",
    "title" => "Listing Name",
    "address" => "Address",
    "Locations" => "Location",
  );

  return $columns;
}
function listing_custom_columns($column){
  global $post;

  switch ($column) {
    case "address":
      $custom = get_post_custom();
      echo $custom["address_meta"][0];
      break;
    case "Locations":
      echo get_the_term_list($post->ID, 'Locations', '', ', ','');
      break;
  }
}

Any help would be appreciated. thank you.

share|improve this question
add comment

2 Answers

I think that in the example you gave, the term that you put in the $filters array has to be lower case since it is a slug. So 'Location' has to be 'location' or whatever the slug is for that taxonomy.

share|improve this answer
    
I tried putting 'locations' in instead of 'Locations' and it then wouldnt give me the list form the taxonomy. Thanks for the suggestion though. –  Brian Artka Jan 10 '11 at 18:58
add comment

I had the exact same problem like you. Don't know why mikeSchinkels code doesn't work anymore. But there are a new (WordPress 3.1) code for this, that works.

I found it here: https://gist.github.com/541505#gistcomment-28441 (in mikes comments)

I replaced mikes code from line 65 to 95, with this code. (check Mikes code on github) Other then that, follow his original structure.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.