[wp-hackers] Adding filter on the top of custom post listing

Mario Peshev mario at peshev.net
Fri Jan 13 17:52:17 UTC 2012


Hello everyone,

I'm listing some data in the WordPress dashboard for a custom post type in
the very regular way - the standard functionality from WP registering the
post type and a custom taxonomy. I'd like to add a filter on the top of the
listing next to the date filter for the taxonomy. In addition to that, each
user can see his own posts only which is an extra filter through
pre_get_posts hook.

It's close to the real deal, but I see many GET parameters in the URL and
after several modifications filter is either not working (changing the
taxonomy ID from the URL doesn't change) or displays 0 to all posts no
matter of the parameter. I've tried to intercept the request and push
there, but no luck.

That's the code I try to use for that sample (modified versions from online
suggestions):

-------------------

add_action('restrict_manage_posts','ulx_filter_categories');

function ulx_filter_categories() {
global $typenow;

 if ($typenow=='customlink'){
                         $args = array(
                             'show_option_all' => "Show All Categories",
                             'taxonomy'        => 'linkcategory',
                             'name'               => 'linkcategory_type'

                         );
 wp_dropdown_categories($args);
            }
}
add_action( 'request', 'my_request' );
function my_request($request) {
if (strpos($GLOBALS['PHP_SELF'], '/wp-admin/edit.php') !== false &&
isset($request['post_type']) && $request['post_type']=='customlink') {
 unset($request['m']);
unset($request['s']);

}
// var_dump($request); die();
return $request;
}


Mario Peshev
Training and Consulting Services @ DevriX
http://www.linkedin.com/in/mpeshev
http://devrix.com
http://peshev.net/blog


More information about the wp-hackers mailing list