2

I have a featured posts slider on my site's front page. It displays n posts (5 right now) from the category featured. If I have 5 posts in that category, and publish a 6th, the oldest of the 6 doesn't show up in the slider or below in the list of all recent posts. My solution right now is to go to All Posts > Published > Featured, pick one to un-feature, and go on with my life.

I'll take suggestions on a better solution (fix the featured slider is probably a decent response), but what I'm looking for here is a way to add a link to All Posts that will show me all published featured posts.

enter image description here

1
  • Hint: That's bulk_actions
    – kaiser
    Commented Feb 28, 2012 at 17:41

1 Answer 1

9

First of all in your image you can see that WordPress lets you filter the posts by category, just bellow the what you have added to the image, But if you want to know how you can add your own link to the filter you can use the views_edit-post filter hook ex:

add_action('pre_get_posts', 'query_add_filter' );
function query_add_filter( $wp_query ) {
    if( is_admin()) {
        add_filter('views_edit-post', 'Add_My_filter');
    }
}

// add filter
function Add_My_filter($views) {
    global $wp_query;
    unset($views['mine']);
    $my_cat = YOUR-CAT-ID

    $query = array(
        'author'      => $current_user->ID,
        'post_type'   => 'post',
        'post_status' => 'publish',
    'cat'         => $my_cat
    );
    $result = new WP_Query($query);
    $class = ($wp_query->query_vars['cat'] == 'featured') ? ' class="current"' : '';
    $views['publish_f'] = sprintf(__('<a href="%s"'. $class .'>Publish Featured <span class="count">(%d)</span></a>', 'publish featured'),
        admin_url('edit.php?post_status=publish&post_type=post&cat='.$my_cat),
        $result->found_posts);

    return $views;
}

just make sure you change YOUR-CAT-ID to the actual category id

6
  • Just to clarify, my current process is: load all posts, load all published posts, filter by featured category. I'm just trying to cut down on loads. Thanks for this answer, I'll play with this tonight and get back to you. Commented Feb 28, 2012 at 19:54
  • Well it makes more sense now that you clarified :) let me know how it works.
    – Bainternet
    Commented Feb 28, 2012 at 21:21
  • I'm finally getting to this.. Where would this hook go? wp-admin/includes/admin.php? Or some other location? Commented Mar 8, 2012 at 20:34
  • That worked. I made a plugin for it. Thank you so much! Commented Mar 8, 2012 at 21:03

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.