WordPress.org

Ready to get started?Download WordPress

Forums

Add taxonomy tabs in admin panel to display all custom posts belonging to it (1 post)

  1. tiwelle
    Member
    Posted 1 year ago #

    Hello,
    As said in the tittle, I'm trying for a while now to get in the admin pannel a tab for taxonomy.
    I have 5 custom post types (Ressources, Biographie, Recueils, Roman, Divers) and for each of them, a taxonomy "Auteurs", and I want my client to be able to query all posts belonging to "Auteurs".
    Ex:
    For "Auteurs" Adam Paul, I have 1 post in Ressources, 1 post in Biographie, 2 posts in "Romans", and I would like to get them in the admin pannel to be able to modify all information at one regarding Adam Paul.
    I was able to query them in front end ( http://www.tiwelle.com/visagevert/auteurs-2/ ), got a drop down fot each post type (see below) but I don't know how to do it to get every post types together.
    Any help ?
    Thank you !
    Manue

    // registers each of the taxonomy filter drop downs
    function sunrise_fbt_add_taxonomy_filters() {
        global $typenow;            // the current post type
        $taxonomies = get_taxonomies('','Auteurs');
        foreach($taxonomies as $taxName => $tax) {
        if(in_array($typenow,$tax->object_type) && $taxName != 'category' && $taxName != 'tags') {
                $terms = get_terms($taxName);
                if(count($terms) > 0) {
                  //Check if hierarchical - if so build hierarchical drop-down
                  if($tax->hierarchical) {
                    $args = array(
                          'show_option_all'    => 'All '.$tax->labels->name,
                          'show_option_none'   => 'Select '.$tax->labels->name,
                          'show_count'         => 1,
                          'hide_empty'         => 0,
                          'echo'               => 1,
                          'hierarchical'       => 1,
                          'depth'              => 3,
                          'name'               => $tax->rewrite['slug'],
                          'id'                 => $tax->rewrite['slug'],
                          'class'              => 'postform',
                          'depth'              => 0,
                          'tab_index'          => 0,
                          'taxonomy'           => $taxName,
                          'hide_if_empty'      => false);
                $args['walker'] = new Walker_FilterByTaxonomy;
                    wp_dropdown_categories($args);
                  } else {
                        echo "<select name='".$tax->rewrite['slug']."' id='".$tax->rewrite['slug']."' class='postform'>";
                        echo "<option value=''>Show All ".$tax->labels->name."</option>";
                        foreach ($terms as $term) {
                  echo '<option value="' . $term->slug . '"', $_GET[$taxName] == $term->slug ? ' selected="selected"' : '','>' . $term->name .' (' . $term->count .')</option>';
                }
                        echo "</select>";
                    }
                }
        }
        }
    }
    add_action( 'restrict_manage_posts', 'sunrise_fbt_add_taxonomy_filters', 100 );
    
    /**
     * Create HTML dropdown list of Categories.
     *
     * @package WordPress
     * @since 2.1.0
     * @uses Walker
     */
    class Walker_FilterByTaxonomy extends Walker {
        var $tree_type = 'category';
        var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
        function start_el(&$output, $category, $depth, $args) {
          $args['selected'] = get_query_var( $args['taxonomy'] );
            $pad = str_repeat(' ', $depth * 3);
    
            $cat_name = apply_filters('list_cats', $category->name, $category);
            $output .= "\t<option class=\"level-$depth\" value=\"".$category->slug."\"";
            if ( $category->slug == $args['selected'] )
                $output .= ' selected="selected"';
            $output .= '>';
            $output .= $pad.$cat_name;
            if ( $args['show_count'] )
                $output .= '  ('. $category->count .')';
            if ( $args['show_last_update'] ) {
                $format = 'Y-m-d';
                $output .= '  ' . gmdate($format, $category->last_update_timestamp);
            }
            $output .= "</option>\n";
            }
    }

Topic Closed

This topic has been closed to new replies.

About this Topic