1

Currently I'm working on a website and I want to separate the header- posts from the rest of the posts in de admin post menu. I added a menu-item which filters the category "header". But I want to exclude the header category from the post-list in the posts-menu.

<?php
add_action('admin_menu', 'events_menu');
function events_menu() {
    add_menu_page(
        'Header',
        'Header',
        'manage_options',
        'edit.php?category_name=header',
        '',
        '',
        4
    );
}
?>

The above code gives me a header menu-item with all the the category header posts. But I can't seem to figure out how to exclude the category header from the post-menu section.

Thanks!

3
  • the pre_get_posts hook should do the trick. You'll have to make sure you write it in a way that it only impacts the admin, otherwise it will filter it out of the loop altogether. It fires before WP_Query. codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts Commented Sep 9, 2016 at 22:35
  • Now that I think of it, why don't you just make your header posts a custom post type? It seem like that would give header posts their own space and keep them out of the standard posts menu. It might be easier to use on the front end as well. Commented Sep 9, 2016 at 22:37
  • Thanks for the advice, Jeremy. I started the custom post type at midnight and I got that working. I got a menu item called "Headers" which is a custom post type and a working loop for reading that post type including a featured image. That worked great! I can't post the solution, because the solution is too long. Thanks again for the advice. Commented Sep 10, 2016 at 16:01

1 Answer 1

0

Reposting as an answer since that solution worked for you. Please accept it as your answer.


Now that I think of it, why don't you just make your header posts a custom post type? It seem like that would give header posts their own space and keep them out of the standard posts menu. It might be easier to use on the front end as well

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.