Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active January 9, 2019 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/2b80cb95223e07faf84b5ec001429228 to your computer and use it in GitHub Desktop.
Save billerickson/2b80cb95223e07faf84b5ec001429228 to your computer and use it in GitHub Desktop.
<?php
/**
* Display only sticky posts
* @see https://displayposts.com/2019/01/09/display-or-hide-sticky-posts/
*
*/
function be_display_only_sticky_posts( $args, $atts ) {
$sticky_variations = array( 'sticky_posts', 'sticky-posts', 'sticky posts' );
if( !empty( $atts['id'] ) && in_array( $atts['id'], $sticky_variations ) ) {
$sticky_posts = get_option( 'sticky_posts' );
$args['post__in'] = $sticky_posts;
}
if( !empty( $atts['exclude'] ) && in_array( $atts['exclude'], $sticky_variations ) ) {
$sticky_posts = get_option( 'sticky_posts' );
$args['post__not_in'] = $sticky_posts;
}
return $args;
}
add_filter( 'display_posts_shortcode_args', 'be_display_only_sticky_posts', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment