If you’re using the Display Posts Shortcode multiple times in one page, or using it on a page with another loop of posts, use this to exclude already displayed posts from new shortcode queries.
Note: you’ll need to modify non-Display Posts Shortcode queries to add those post IDs to the global variable. This snippet is using a global variable found in the Genesis theme that already stores the list of displayed posts.
/**
* Exclude displayed posts from DPS query
*
*/
function be_dps_exclude_displayed_posts( $args ) {
global $_genesis_displayed_ids;
$args['post__not_in'] = !empty( $args['post__not_in'] ) ? array_merge( $args['post__not_in'], $_genesis_displayed_ids ) : $_genesis_displayed_ids;
return $args;
}
add_filter( 'display_posts_shortcode_args', 'be_dps_exclude_displayed_posts' );
/**
* Add DPS posts to exclusion list
*
*/
function be_dps_add_posts_to_exclusion_list( $output ) {
global $_genesis_displayed_ids;
$_genesis_displayed_ids[] = get_the_ID();
return $output;
}
add_filter( 'display_posts_shortcode_output', 'be_dps_add_posts_to_exclusion_list' );