Consider this: I've got a custom post type 'portfolio' these posts, or "portfolio items" all have several categories such as: "photography", "concepting", "branding" , "clientA" , "clientB" etc.

Now I want to build a custom backend sollution to let the user create a pool of "Special categories" which I eventualy want to use to create a query containing every "portfolio item" that has at least one of these categories.

So for example: I have the following portfolio items with the following categories:

  1. "Item1" - "photography","concepting","clientA"
  2. "Item2" - "concepting","clientB"
  3. "Item3" - "branding","clientC"

The sollution I want to create for the backend should let the user create an array of categories, where they can choose from every category that is linked to a portfolio item.

So If the user added: "clientA" and "clientB" to this sollution, then I want my query to return "Item1" & "Item2".

How would I go about creating a tool for the user that lets them fill an array of categories, that I can later use to define a query?

I think I need to create a custom menu page that lists all categories linked to a post and then via checkmarks create the array of categories. But I'm not sure how to create and store this array.

My actual plugin based on Pabamato's answer:

add_action( 'admin_menu', 'show_specific_cats' );    

function show_specific_cats() {
    add_menu_page('Kies de categories', 'Manage categories', 'manage_options', 'show-spec-cats', 'category_options');

function category_options() {
    if ( !current_user_can( 'manage_options' ) )  {
        wp_die( __( 'You do not have sufficient permissions to access this page.' ) );

    $categories = get_terms( 'category', 'orderby=count&hide_empty=0' );

    if($_POST) {
        $theCats = [];
        foreach($_POST  as $key => $value) {
            array_push($theCats , $value);
        update_option( 'show_these_cats', $_POST );

    $showTheseCats = get_option('show_these_cats');

    echo '<form method="post">';
        echo '<input type="hidden" name="empty" value="0" />';
        echo '<ul>';
        foreach($categories as $key => $value){
            echo '<li>'.
                '<input type="checkbox" name="checkbox[]"';
                if(in_array($value->term_id, $showTheseCats['checkbox'])) {
                    echo 'checked';
                ' value="'.
        echo '</ul>';
        echo '<input type="submit" value="Opslaan">';
    echo '</form>';

The array of categories can be called via the custom option show_these_cats.

My query on page is now like this:

    $showTheseCats = get_option('show_these_cats');
        $args = 'cat='. implode(', ', $showTheseCats[checkbox]).'';
        query_posts( $args );

        while ( have_posts() ) : the_post();
            echo '<li>';
            echo '</li>';

1 Answer 1


You can use


to return the needed data for the select, and store the selected values (term IDs) in options table using


The 'hide_empty' param in 'get_terms' will prevent returning categories with no posts.

  • This is an awesome idea. I'll update my question with my final plugin once I Implemented your idea. Oct 27, 2015 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.