Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Say I have 3 categories: A, B, C, and another category D that posts in A,B,C can also be assigned to. D is to denote the featured post for the category, and theoretically only one post for each (A, B, C) will also be assigned D.

I can find the featured post for each category fine using category__and .

I have a need to make a list of the rest of the category minus the featured post to the right of the featured post on the home page. So for example I want to get a list of category A but I want to exclude the featured post that would be marked category A and category D.

I tried using "category_in" followed by "category_not_in" thinking it would accomplish this but the "category__not_in" seems to override and just find everything in every category except for the excluded category.

If I have things structured wrong please let me know. I am trying to make things simple for the site owner by not having to remember to enter text for a tag (featured post). I'd rather them just check the check boxes in the category list.

Summarizing, my code needs to do two things. For example:

Find the "featured post": FIND A and D . This is done. Find everything in the category EXCEPT featured post: Find A, exclude (A and D).

Any help would be greatly appreciated. I'm new to Wordpress but not coding. Just trying to get acquainted with the functionality.

share|improve this question
1  
As G.M. mentioned below, is there a reason you're not using sticky posts for your 'featured' items (instead of a separate category)? codex.wordpress.org/Sticky_Posts –  Andy Adams Aug 30 '13 at 16:53
add comment

1 Answer

This is probably not a "pure" way to do it, but this code make an array of featured post ids and then excludes them from future get_posts.

$featuredPosts = get_posts('category'=>'D','numberposts'=>'-1');
$fPId = array();
foreach ($featuredPost as $currentPost)
{
  array_push($fPId,$currentPost->ID);
}
$aPosts = get_posts('category' => 'a', 'exclude'=>$fpId);
$bPosts = get_posts('category' => 'b', 'exclude'=>$fpId);
$cPosts = get_posts('category' => 'c', 'exclude'=>$fpId);
share|improve this answer
    
Ah! I didn't even think of taking that angle. I'll give it a try. Thanks! –  Craig Coston Jul 19 '12 at 6:30
    
@CraigCoston Fixed a syntax error –  fdsa Jul 19 '12 at 22:10
1  
Wordpress as a core function sticky posts that is intended for that purpose. Get only sticky posts: 'post__in' => get_option( 'sticky_posts' ), exclude stycky posts: 'post__not_in' => get_option( 'sticky_posts' ) faster, simpler and most reliable on theme changing. –  G. M. Jul 26 '13 at 10:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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