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.

Possible Duplicate:
featuring old articles without messing up with the archive

Let's say you have a category called "featured". and you use that to feature posts. And the theme you have has a zone to show those featured posts and has room to show the last 5 featured posts in there.

And you want to make the admin work as easy as possible to the degree that you only want to find yourself checking the posts into that "featured" category and you do NOT want to uncheck them later. You are basically only checking, and never unchecking.

The problem is WP uses post_data to find out the most recent posts. But then, what do you do when you want to feature a very old post? how do you deal with that? Change the post_date?

If you were to select that post into the "featured" category, that post is not going to make it into the top 5 because the other posts that happened to be "featured" and more recent may easily be pushing it down.

In this case, I got no choice but change the the post_date of the article and this seems totally wrong to me. Because this definitely messes the ARCHIVE data integrity. Your 5 year old post will appear as brand new.

What solutions are out there to address this problem?

I almost think that the wp_posts table should have a special field called "post_feature_date".

If we were to use the "sticky posts" feature, that's not gonna cut it neither because remember, I'm only interested in checking things, NOT UNCHECKING THINGS.

If you got a simple blog, I do understand that this issue is not a matter but if you are using the WP to the rim in managing a huge portal, then you want to save every maintenance step as possible.

share|improve this question
    
Dublicate of a question of @AverageJoe himself a week ago. –  kaiser May 1 '12 at 17:28
add comment

marked as duplicate by kaiser, EAMann May 1 '12 at 18:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3 Answers

The problem is that you misuse the category field.

Use a site meta field (array) and a simple checkbox on each post. When a post is saved add its ID to the site meta array, and if the array is longer than 5 drop the last ID from it. The query for featured post will then just take the post IDs from the meta field and you will never have to uncheck something manually.

share|improve this answer
1  
I would also add if you still want to drill down into a category, use a custom taxonomy and a meta field, not the default post "category". –  Wyck May 1 '12 at 3:23
    
@toscho but that's adfitional work which I'm trying to avoid. I'm talking about taking the id and inserting it etc. should not featuring posts be as simple as checking the featured category? –  Average Joe May 1 '12 at 12:15
    
@AverageJoe It takes 20 minutes to write that code. I don't get your point. –  toscho May 1 '12 at 12:26
add comment

How about this?

Hook a function into update post which checked whether a post has been newly added to the featured posts category ( see below for an idea on how ) If it has been newly added then add the current date to a custom field (post_feature_date) Now you cam base your featured posts after "featured date" instead of "published date"

You should also check on update post whether a post was removed from the featured category and if so set it's post_feature_date custom field to null so that you could use that to determine whether a post was "in" the featured category ( ie the assumption being that if a post was in featured it should have a date in post_feature_date so conversely if post_feature_date is null on update post then the post had not been in featured category )

share|improve this answer
    
@byrunasgur that's exactly what I had in mind. But I could not figure out how to handle the future date featuring thing. You may be planning to feature a post say 4 days ahead. Do you see how that can be done too? –  Average Joe May 1 '12 at 12:21
    
Also, i have performance concerns as far as pulling the featured posts thru custom fields (wp_postmeta). if wp_post table had one more field called post_feature_date, this would not have been an issue. –  Average Joe May 1 '12 at 13:08
1  
Not sure what you mean about planning to feature a post, surely if you got the above working then it would be irrelevant at what time you set it to be featured? As regards the performance I haven't much experience in this area but I think I know what you mean. I can see how another date would be helpful. I did an events manager recently and ran into a similar problem with published date VS event date. I think maybe some general purpose date would be good to have. I don't think you'll get any hop about it here though, maybe try WordPress Trac –  byronyasgur May 1 '12 at 23:45
add comment

Here's how I approach this:

Create a metabox that creates a custom field, called 'feature_on_homepage' with values of 'Yes'and 'No' and show it on the edit post page. This can be done in functions.php, or you can use something like WPAlchemy MetaBox PHP Class, which abstracts it a little, or even the More Fields plugin or something similar.

By default, leave this metabox checked to 'No'. We can then run a custom query to get X number of posts in a particular category that have the 'feature_on_homepage' metabox with a value of 'Yes' and then sort by modified:

$showFeaturedPost->query( 'cat=1&orderby=modified&post_type=post&meta_key=feature_on_homepage&meta_value=Yes&posts_per_page=5' );

share|improve this answer
    
Why not use sticky posts? –  mrwweb May 1 '12 at 4:09
    
@mrwweb You have to change the front-page query and the back-end labels to use sticky posts for that. –  toscho May 1 '12 at 9:50
    
@davemac that won't help. Because post modified gets updated in pretty much everything you do with the post. Such as adding a new tag or correcting a spelling error somewhere within the post. The solution cannot have anything to do with post modified. –  Average Joe May 1 '12 at 12:18
add comment

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