<?phpfunctionneed_sticky($post){$post_type=$post->post_type;$post_type_object=get_post_type_object($post_type);$can_publish=current_user_can($post_type_object->cap->publish_posts);return$can_publish&&in_array($post->post_type,array('page','event'));}add_action('post_submitbox_minor_actions','w_post_submitbox_minor_actions');functionw_post_submitbox_minor_actions($post){if(need_sticky($post)){ob_start();}}add_action('post_submitbox_misc_actions','w_post_submitbox_misc_actions');functionw_post_submitbox_misc_actions($post){if(need_sticky($post)){$temp=ob_get_clean();$sticky_box='<input type="checkbox" style="display:none" name="hidden_post_sticky" id="hidden-post-sticky" value="sticky" '.checked(is_sticky($post->ID),true,false).' />';if(current_user_can('edit_others_posts')){$sticky_box.=sprintf('<span id="sticky-span"><input id="super-sticky" name="sticky" type="checkbox" value="sticky" %1$s /> <label for="super-sticky" class="selectit">%2$s</label><br/></span>',checked(is_sticky($post->ID),true,false),__('Stick this post to the front page'));}$re='/(<input.*id="visibility-radio-password")/U';$output=preg_replace($re,"{$sticky_box}$1",$temp);echo$output;}}
<?php// If ACF field `sticky_posts` is on an option pageadd_filter('pre_option_options_sticky_posts','w_get_sticky');functionw_get_sticky(){returnget_option('sticky_posts');}add_action('update_option','w_update_sticky',10,3);functionw_update_sticky($option,$old_value,$value){if('options_sticky_posts'===$option){update_option('sticky_posts',$value);}}// If ACF field `sticky_posts` is a page_for_posts metaboxadd_filter('get_post_metadata','w_get_sticky_post_meta',10,3);functionw_get_sticky_post_meta($check,$object_id,$meta_key){if(get_option('page_for_posts')==$object_id&&'sticky_posts'===$meta_key){returnarray(get_option('sticky_posts'));}return$check;}add_action('updated_post_meta','w_update_sticky_post_meta',10,4);functionw_update_sticky_post_meta($meta_id,$object_id,$meta_key,$_meta_value){if(get_option('page_for_posts')==$object_id&&'sticky_posts'===$meta_key){update_option('sticky_posts',$_meta_value);}}
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.