3

I am logged on as admin

I am on the Posts dashboard

I have Posts assigned to multiple Categories and I have posts that are assigned to only one category.

I want to display posts that are assigned to only one category.

if a post is assigned to multiple categories, then it that post should not be displayed.

The result should be posts that are assigned to one category and as I edit them and assign them to more than one category, the Post will not show in the List after I click save.

How can this be done?

1 Answer 1

0

You can hook into the load-edit.php action to modify how wp-admin lists pages. Add this to your functions.php:

<?php

add_action( 'load-edit.php', 'namespace_modify_admin_list' );

function namespace_modify_admin_list() {
    global $typenow;

    if ( 'post' !== $typenow )
        return;

    add_action( 'pre_get_posts', 'namespace_modify_admin_list_posts' );
}

function namespace_modify_admin_list_posts( $query ) {
    /**
     * Modify query here to change how posts are listed, using
     * the set method of the query object.
     *
     * Example:
     * $query->set( 'posts_per_page', 10 );
     */
}

?>

May I ask why would you want to hide posts that have more than one category? Is this for access-control or filtering purposes?

3
  • Absolutely, I have thousands of posts, and I am importing more every day. Each post gets imported into a specific category. After the import I have to search for specific phrases and based upon each phrase, the Post will be assigned to an additional category. I am trying to make it easier to just be presented with those Posts that I have to assign to an additional category. Commented Mar 8, 2017 at 13:57
  • I added the code but nothing is changing on my Post page. Commented Mar 8, 2017 at 23:23
  • I'm a bit confused... what exactly do you want the site to do? Which part of wp-admin do you want to hide the posts in? Also, what's the code you used for the load-edit.php action?
    – ricotheque
    Commented Mar 9, 2017 at 5:39

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.