1

After much headache in the last week I feel like my problem is almost solved. I have been attempting to customize the admin edit.php page of custom post types to display and sort/filter custom taxonomies. I've frankensteined a collection of actions and filters from things found on the web but fear I may be using deprecated code as some of them were quite old.

I think I've narrowed the problem down to this filter

add_filter('parse_query','convert_large_feature_id_to_taxonomy_term_in_query');
function convert_large_feature_id_to_taxonomy_term_in_query($query) {
    global $pagenow;
    $qv = &$query->query_vars;
    if ($pagenow=='edit.php' &&
            isset($qv['taxonomy']) && $qv['taxonomy']=='large_feature' &&
            isset($qv['term']) && is_numeric($qv['term'])) {
        $term = get_term_by('id',$qv['term'],'large_feature');
        $qv['term'] = $term->slug;
    }
}   

When I choose the dropdown menu for large_feature it accurately displays the "categories" (is that what you call them when they are of a custom taxonomy?) and post count, however when it is actually filtered, the query comes up empty. I noticed, however, that when I modified the query URL from

http://www.ampeg.com/2012/wp-admin/edit.php?post_status=all&post_type=ampeg_artists&action=-1&m=0&cat=0&large_feature=291&paged=1&mode=list&action2=-1

to

http://www.ampeg.com/2012/wp-admin/edit.php?post_status=all&post_type=ampeg_artists&action=-1&m=0&cat=0&large_feature=home_page_large&paged=1&mode=list&action2=-1

It displays as intended.

This leads me to believe that this filter isn't outputting the slug as it's supposed to... right?

1

taxonomy & term won't be set (in this case), since query vars are mapped from GET/POST.

In other words, $qv['large_feature'] = 291 (see wp_edit_posts_query() and WP_Query::get_posts() for the big picture).

add_filter( 'parse_query','convert_large_feature_id_to_taxonomy_term_in_query' );

function convert_large_feature_id_to_taxonomy_term_in_query( $query ) {
    global $pagenow;

    $qv =& $query->query_vars;

    if (
        $pagenow == 'edit.php' &&
        isset( $qv['large_feature'] ) &&
        ctype_digit( $qv['large_feature'] ) // stricter than is_numeric()
    ) {
        if ( $term = get_term_by( 'id', $qv['large_feature'], 'large_feature' ) )
            $qv['large_feature'] = $term->slug;
    }
} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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