Guest User

filter on custom taxonomies

a guest
Jul 23rd, 2010
38
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_action( 'init', 'create_ressource_fr_post_types' );
  2.  
  3. function create_ressource_fr_post_types() {
  4. register_post_type( 'ressource_fr',
  5. array(
  6. 'labels' => array(
  7. 'name' => __( 'Ressources FR' ),
  8. 'singular_name' => __( 'Ressource FR' ),
  9. 'add_new' => __( 'Ajouter' ),
  10. 'add_new_item' => __( 'Ajouter une nouvelle ressource de français' ),
  11. 'edit' => __( 'Modifier' ),
  12. 'edit_item' => __( 'Modifier une ressource' ),
  13. 'new_item' => __( 'Nouvelle ressource' ),
  14. 'view' => __( 'Afficher la ressource' ),
  15. 'view_item' => __( 'Afficher la ressource' ),
  16. 'search_items' => __( 'Chercher dans les ressources de français' ),
  17. 'not_found' => __( 'Aucune Ressource trouvée' ),
  18. 'not_found_in_trash' => __( 'Pas de ressources trouvée dans la corbeille' ),
  19. 'parent' => __( 'Ressource parent' )
  20. ),
  21. 'public' => true,
  22. 'hierarchical' => true,
  23. 'supports' => array( 'title', 'editor', 'page-attributes' ),
  24. 'query_var' => true,
  25. 'rewrite' => true,
  26. )
  27. );
  28. }
  29.  
  30. add_action( 'init', 'register_profperso_taxonomies', 0 );
  31.  
  32. function register_profperso_taxonomies() {
  33.  
  34. register_taxonomy(
  35. 'classement_fr',
  36. array( 'ressource_fr' ),
  37. array(
  38. 'public' => true,
  39. 'hierarchical' => true,
  40. 'labels' => array(
  41. 'name' => __( 'Classements FR' ),
  42. 'singular_name' => __( 'Classement FR' )
  43. ),
  44. 'query_var' => 'classement-fr',
  45. 'rewrite' => array( 'slug' => 'cours-fr' ),
  46. )
  47. );
  48.  
  49. }
  50.  
  51. add_action( 'restrict_manage_posts','my_restrict_manage_posts' );
  52.  
  53. function my_restrict_manage_posts() {
  54. global $typenow;
  55. if ($typenow=='ressource_fr')
  56. wp_dropdown_categories( 'show_option_all=Afficher tout&show_count=1&hierarchical=1&taxonomy=classement_fr&name=classement_fr');
  57.  
  58. }
  59.  
  60. add_action( 'request', 'my_request' );
  61. function my_request($request) {
  62. if (isset($request['post_type']) && $request['post_type']=='ressource_fr') {
  63. $request['taxonomy'] = 'classement_fr';
  64. $request['term'] = get_term($request['classement-fr'],'classement_fr')->name;
  65. unset($request['name']);
  66. }
  67. return $request;
  68. }
RAW Paste Data