-
-
Save billerickson/bbd0555ef0993fb617cc4bcec664eca3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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