Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active April 17, 2020 14:30
Show Gist options
  • Save billerickson/bbd0555ef0993fb617cc4bcec664eca3 to your computer and use it in GitHub Desktop.
Save billerickson/bbd0555ef0993fb617cc4bcec664eca3 to your computer and use it in GitHub Desktop.
<?php
/**
* Exclude displayed posts from Display Posts
* @see https://displayposts.com/2019/01/03/exclude-posts-already-displayed/
*/
function be_dps_exclude_displayed_posts( $args ) {
global $dps_excluded_posts;
if( ! is_array( $dps_excluded_posts ) )
$dps_excluded_posts = [];
$args['post__not_in'] = !empty( $args['post__not_in'] ) ? array_merge( $args['post__not_in'], $dps_excluded_posts ) : $dps_excluded_posts;
return $args;
}
add_filter( 'display_posts_shortcode_args', 'be_dps_exclude_displayed_posts' );
/**
* Add DPS posts to exclusion list
* @see https://displayposts.com/2019/01/03/exclude-posts-already-displayed/
*/
function be_dps_add_posts_to_exclusion_list( $output ) {
global $dps_excluded_posts;
if( ! is_array( $dps_excluded_posts ) )
$dps_excluded_posts = [];
$dps_excluded_posts[] = get_the_ID();
return $output;
}
add_filter( 'display_posts_shortcode_output', 'be_dps_add_posts_to_exclusion_list' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment