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.

Total WP and web development noob here.

As the title suggests, I'm trying to make all the posts in one of my categories into "stickied" posts. But so far I've had no luck.

What I've tried is this sexy little snippet of code:

<?php 
if (in_category('bestcategoryever')) {
stick_post(); }
?>

...but to no avail. Perhaps I'm not putting it in the right place (not quite sure where I should put it really) or perhaps it's wrong to start with.

Please explain thoroughly and plainly, my terminology in these things isn't the best.

I hope you can help me!

Cheers!

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You rather need a save_post hook. Check following code it marks the post sticky for the specified if it is not already.

add_action( 'save_post', 'mark_post_sticky' );
function mark_post_sticky( $post_id ) {

    if ( !wp_is_post_revision( $post_id ) && !isset($_POST['sticky']) &&
        in_category('bestcategoryever',$post_id) ) {

        $_POST['sticky'] = 'sticky';        
    }
}
share|improve this answer
    
Thanks for your help! Unfortunately it's not working. Where do I implement this? I tried the index.php but as I'm quite the novice to this type of stuff so I can't say quite what I'm doing wrong. It's very frustrating. This is the theme that I'm using. –  burnso Jul 31 '13 at 17:08
    
You need to paste it in functions.php in your theme. –  M-R Jul 31 '13 at 18:31
    
Thanks! That did it. :) –  burnso Jul 31 '13 at 19:20
    
Hey again! Quick question, what would I have to change in the code above to mark all posts in a category as 'not sticky'? Thanks again! –  burnso Aug 2 '13 at 23:32
    
If you meant to restricting admin to not making post sticky of category. You would call unset($_POST['sticky']);. However if you want to make all posts sticky would have different solution. Please post a new question. –  M-R Aug 3 '13 at 13:23
show 4 more comments

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.