看起来这是可能的。
Sticky posts作为ID数组存储在名为“Sticky\\u posts”的选项中,您可以使用挂钩修改选项,以便。。。这样的事情很有可能奏效:
function fake_sticky_posts_for_author() {
$user = wp_get_current_user();
if ( get_current_user_id() && in_array(\'author\', $user->roles) ) {
// Return the IDs of posts that you want to see as sticky
// For example this gets posts of currently logged in user
return get_posts( array(
\'author\' => get_current_user_id(),
\'fields\' => \'ids\',
\'posts_per_page\' => -1
) );
}
return false;
}
add_filter( \'pre_option_sticky_posts\', \'fake_sticky_posts_for_author\' );
// we use pre_option_sticky_posts in here, since we want to ignore value of this option, so there is no point to load it
另一方面,如果您想将任何作者撰写的所有帖子设置为粘性,那么还有另一种方法可能更好(更有效)。你可以随时查看
save_post
如果作者已指定角色并将其设置为粘滞,如果是:
function stick_authors_posts_automatically($post_id) {
// If this is just a revision, don\'t do anything
if ( wp_is_post_revision( $post_id ) )
return;
$user = new WP_User( get_post_field (\'post_author\', $post_id) );
if ( in_array(\'author\', $user->roles) ) {
// stick the post
stick_post( $post_id );
}
}
add_action( \'save_post\', \'stick_authors_posts_automatically\' );
免责声明:此代码未经测试,所以可能有一些拼写错误等。但我希望想法很清楚:)