[wp-hackers] Custom Post Type in Admin, filter by new custom Taxonomies

Frank Bueltge frank at bueltge.de
Fri Jul 23 12:22:46 UTC 2010


this works fine on me:

i define the taxonomie and post_type via constant:
	define( 'FB_CPT_POST_TYPE_1', 'quotes' );
	define( 'FB_CPT_TAXONOMY_TYPE_1', 'authors' );

the two fucntion from Mike:
		function get_taxonomy_html_select($taxonomy_name, $args) {
			
			$taxonomy = get_taxonomy($taxonomy_name);
			$terms = get_terms($taxonomy_name, $args);
			$label = __( 'Show All ' . $taxonomy->label, FB_CPT_TEXTDOMAIN );
			$html = array();
			$html[] = '<select id="' . $taxonomy_name . '" name="' .
$taxonomy_name . '">';
			$html[] = '<option value="0">' . $label . '</option>';
			$this_term = $_GET[$taxonomy_name];
			foreach($terms as $term) {
				$default = ($this_term == $term->term_id ? ' selected="selected"' : '');
				$value = esc_attr($term->name);
				$value = $value . ' (' . (int)$term->count . ') ';
				$html[] = '<option value="' . $term->term_id . '"' . $default .
'>' . $value . '</option>';
			}
			$html[] = '</select>';
			return implode( "\n", $html );
		}
		
		function request($request) {
			global $pagenow;
			
			if ( is_admin() && 'edit.php' == $pagenow && isset(
$request['post_type'] ) && FB_CPT_POST_TYPE_1 == $request['post_type']
) {
				$request['taxonomy'] = FB_CPT_TAXONOMY_TYPE_1;
				$request['term'] = get_term($request[FB_CPT_TAXONOMY_TYPE_1],
FB_CPT_TAXONOMY_TYPE_1)->name;
				unset($request['name']);
				
			}
			
			return $request;
		}


On Fri, Jul 23, 2010 at 2:19 PM, Jimmy Roy <jimmy.roy at gmail.com> wrote:
> function my_request($request) {
>       //if (isset($request['post_type']) &&
> $request['post_type']=='ressource_fr') {
>       if ( is_admin() && '/wp3.0/profperso/wp-admin/edit.php' ==
> $GLOBALS['PHP_SELF'] && isset( $request['post_type'] ) &&
> $request['post_type'] == 'ressource_fr' ) {
>               $request['taxonomy'] = 'classement_fr';
>               $request['term'] =
> get_term($request['classement-fr'],'classement_fr')->name;
>               print_r($request);
>               unset($request['name']);
>       }
>       return $request;
> }
>
> it print :
>
> Array ( [order] => asc [orderby] => menu_order title [post_type] =>
> ressource_fr [posts_per_page] => -1 [posts_per_archive_page] => -1
> [taxonomy] => classement_fr [term] => )
>
> term is empty, maybe it's the reason.
>
>
> 2010/7/23 Mike Schinkel <mikeschinkel at newclarity.net>
>
>> Jimmy,
>>
>> I don't know.  You've got something about your implementation that I can't
>> figure out.  Maybe someone else can.  Sorry.
>>
>> -Mike
>>
>> On Jul 23, 2010, at 7:36 AM, Jimmy Roy wrote:
>>
>> > actually at first it was name-classement-fr, then I change to try.
>> >
>> > the difference is :
>> > name=classement_fr : chose a custom taxonomy andclick on filter return
>> all
>> > results in any case.
>> > name=classement-fr : chose a custom taxonomy andclick on filter return no
>> > result in any case.
>> >
>> > Jimmy
>> >
>> > 2010/7/23 Mike Schinkel <mikeschinkel at newclarity.net>
>> >
>> >> In http://pastebin.com/PL1FWtcs line 56 uses "name=classement_fr"
>> whereas
>> >> line 64 uses "$request['classement-fr']" and they don't match.  Change
>> line
>> >> 56 to be "name=classement-fr".
>> >>
>> >> -Mike
>> >>
>> >> On Jul 23, 2010, at 7:19 AM, Jimmy Roy wrote:
>> >>
>> >>> Mike,
>> >>> classement_fr is the name of the taxonomy.
>> >>> classement-fr is the value of the query_var argument.
>> >>>
>> >>> Jimmy
>> >>>
>> >>>
>> >>>
>> >>> 2010/7/23 Mike Schinkel <mikeschinkel at newclarity.net>
>> >>>
>> >>>> Jimmy,
>> >>>>
>> >>>> I just noticed, '[classement_fr] => 6' is not in your array.
>> >>>>
>> >>>> First try to use either "classement_fr" everywhere or "classement-fr"
>> >> and
>> >>>> see if that fixes it.
>> >>>>
>> >>>> -Mike
>> >>>>
>> >>>> On Jul 23, 2010, at 6:32 AM, Jimmy Roy wrote:
>> >>>>
>> >>>>> Array ( [order] => asc [orderby] => menu_order title [post_type] =>
>> >>>>> ressource_fr [posts_per_page] => -1 [posts_per_archive_page] => -1 )
>> >>>>>
>> >>>>> url after clicking "filter" button :
>> >>>>>
>> >>>>>
>> >>>>
>> >>
>> http://localhost:8888/wp3.0/profperso/wp-admin/edit.php?s&post_status=all&post_type=ressource_fr&mode=list&action=-1&m=0&classement_fr=6&action2=-1
>> >>>>>
>> >>>>>
>> >>>>> 2010/7/23 Mike Schinkel <mikeschinkel at newclarity.net>
>> >>>>>
>> >>>>>> What do you get in the view source when you using this instead:
>> >>>>>>
>> >>>>>> function request($request) {
>> >>>>>>     print_r($request);
>> >>>>>>     exit;
>> >>>>>> }
>> >>>>>>
>> >>>>>> Also, what's your URL after clicking the "Filter" button?
>> >>>>>>
>> >>>>>> -Mike
>> >>>>>>
>> >>>>>>
>> >>>>>> On Jul 23, 2010, at 6:02 AM, Jimmy Roy wrote:
>> >>>>>>
>> >>>>>>> now, when I click on filter button the result is always the same,
>> all
>> >>>>>> list
>> >>>>>>> of ressources.
>> >>>>>>>
>> >>>>>>> my code :
>> >>>>>>>
>> >>>>>>> add_action( 'init', 'register_profperso_taxonomies', 0 );
>> >>>>>>>
>> >>>>>>> function register_profperso_taxonomies() {
>> >>>>>>>
>> >>>>>>> register_taxonomy(
>> >>>>>>> 'classement_fr',
>> >>>>>>> array( 'ressource_fr' ),
>> >>>>>>> array(
>> >>>>>>> 'public' => true,
>> >>>>>>> 'hierarchical' => true,
>> >>>>>>> 'labels' => array(
>> >>>>>>> 'name' => __( 'Classements FR' ),
>> >>>>>>> 'singular_name' => __( 'Classement FR' )
>> >>>>>>> ),
>> >>>>>>> 'query_var' => 'classement-fr',
>> >>>>>>>     'rewrite' => array( 'slug' => 'cours-fr' ),
>> >>>>>>> )
>> >>>>>>> );
>> >>>>>>> }
>> >>>>>>>
>> >>>>>>>
>> >>>>>>> // pour filtrer les ressources par classement
>> >>>>>>> add_action( 'restrict_manage_posts','my_restrict_manage_posts' );
>> >>>>>>>
>> >>>>>>> function my_restrict_manage_posts() {
>> >>>>>>> global $typenow;
>> >>>>>>> if ($typenow=='ressource_fr')
>> >>>>>>> wp_dropdown_categories( 'show_option_all=Afficher
>> >>>>>>>
>> >>>>>>
>> >>>>
>> >>
>> tout&show_count=1&hierarchical=1&taxonomy=classement_fr&name=classement_fr');
>> >>>>>>> }
>> >>>>>>>
>> >>>>>>> add_action( 'request', 'my_request' );
>> >>>>>>> function my_request($request) {
>> >>>>>>>    if (isset($request['post_type']) &&
>> >>>>>>> $request['post_type']=='ressource_fr') {
>> >>>>>>>            $request['taxonomy'] = 'classement_fr';
>> >>>>>>>            $request['term'] =
>> >>>>>>> get_term($request['classement-fr'],'classement_fr')->name;
>> >>>>>>>            unset($request['name']);
>> >>>>>>>    }
>> >>>>>>>    return $request;
>> >>>>>>> }
>> >>>>>>>
>> >>>>>>> generated html :
>> >>>>>>> <select id="classement_fr" name="classement_fr"> <option
>> >> value="0">Show
>> >>>>>> All
>> >>>>>>> Classements FR</option> <option value="5">Langue oral</option>
>> >> <option
>> >>>>>> value
>> >>>>>>> ="6">Niveau 1</option> <option value="7">Niveau 2</option> <option
>> >>>>>> value="8
>> >>>>>>> ">Niveau 3</option> </select><input type="submit"
>> >>>> id="post-query-submit"
>> >>>>>>> value="Filtrer" class="button-secondary" />
>> >>>>>>> _______________________________________________
>> >>>>>>> wp-hackers mailing list
>> >>>>>>> wp-hackers at lists.automattic.com
>> >>>>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>> >>>>>>
>> >>>>>> _______________________________________________
>> >>>>>> wp-hackers mailing list
>> >>>>>> wp-hackers at lists.automattic.com
>> >>>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>> >>>>>>
>> >>>>> _______________________________________________
>> >>>>> wp-hackers mailing list
>> >>>>> wp-hackers at lists.automattic.com
>> >>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>> >>>>
>> >>>> _______________________________________________
>> >>>> wp-hackers mailing list
>> >>>> wp-hackers at lists.automattic.com
>> >>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>> >>>>
>> >>> _______________________________________________
>> >>> wp-hackers mailing list
>> >>> wp-hackers at lists.automattic.com
>> >>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>> >>
>> >> _______________________________________________
>> >> wp-hackers mailing list
>> >> wp-hackers at lists.automattic.com
>> >> http://lists.automattic.com/mailman/listinfo/wp-hackers
>> >>
>> > _______________________________________________
>> > wp-hackers mailing list
>> > wp-hackers at lists.automattic.com
>> > http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list