• First of all, congratulations on the plugin, it is very helpful!

    Is there any way I can customize it for filtering a different post type? On the theme I am working with, there is a post type called Wiki, Id like to filter just as you did on pages. Thank you!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Did you have any luck with this? I am trying to do the same…

    It seemed like it should be easy to replace the checks against ‘page’ with your custom type, as long as it is hierarchical. But that is not working for me.

    Thread Starter gcacciola

    (@gcacciola)

    jtrip how experienced is you with coding and wordpress? I am no coder but I am great at googling and copying and pasting codes hahaha.

    I had no answer but I ended up “adapting” the code for my own needs.

    If you think you can do it, send me a PM and I’ll send you what I did, but you’ll have to adapt yourself.

    I hope it helps.

    Hi gcacciola, I am _fairly_ experienced at this point, more comfortable with PHP than wordpress in particular but I have been able to implement a few good features…

    I took a look at the code and I was able to get it to work for me, at least so far I believe, not sure what kind of troubles I might run into.

    I would love to try and work with the dev on expanding the functionality of this plugin but probably not until I see a GitHub or other public project. I’ll PM you what I did in the mean time.

    @gcacciola I can’t seem to find how to PM you. Are you on twitter or GitHub?

    Thread Starter gcacciola

    (@gcacciola)

    Lol, I can’t either. I’ll post the code here. Whatever.

    The plugin is to filter a custom post type called WIKI, and i want to filter it by the taxonomy called wiki-category.

    I hope it helps.

    <?php
    /**
    * Plugin Name: Categoria-Wiki
    * Display a custom taxonomy dropdown in admin
    * @author Mike Hemberger
    * @link https://thestizmedia.com/custom-post-type-filter-admin-custom-taxonomy/
    */
    add_action('restrict_manage_posts', 'tsm_filter_post_type_by_taxonomy');
    function tsm_filter_post_type_by_taxonomy() {
    global $typenow;
    $post_type = 'wiki'; // change to your post type
    $taxonomy = 'wiki-category'; // change to your taxonomy
    if ($typenow == $post_type) {
    $selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
    $info_taxonomy = get_taxonomy($taxonomy);
    wp_dropdown_categories(array(
    'show_option_all' => __("Show All {$info_taxonomy->label}"),
    'taxonomy' => $taxonomy,
    'name' => $taxonomy,
    'orderby' => 'name',
    'selected' => $selected,
    'show_count' => true,
    'hide_empty' => true,
    ));
    };
    }
    /**
    * Filter posts by taxonomy in admin
    * @author Mike Hemberger
    * @link https://thestizmedia.com/custom-post-type-filter-admin-custom-taxonomy/
    */
    add_filter('parse_query', 'tsm_convert_id_to_term_in_query');
    function tsm_convert_id_to_term_in_query($query) {
    global $pagenow;
    $post_type = 'wiki'; // change to your post type
    $taxonomy = 'wiki-category'; // change to your taxonomy
    $q_vars = &$query->query_vars;
    if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0 ) {
    $term = get_term_by('id', $q_vars[$taxonomy], $taxonomy);
    $q_vars[$taxonomy] = $term->slug;
    }
    }

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Side note: there is no PM here and people are discouraged from contact other people directly for support.

    Thread Starter gcacciola

    (@gcacciola)

    Alright, its best to leave people without solutions. 3 months with no answer is fine.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Can I customize the code so It can work for different post types?’ is closed to new replies.