Skip to content

Instantly share code, notes, and snippets.

@reasonstousegenesis
Created November 16, 2015 04:07
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 reasonstousegenesis/cfdec91f99f06516b6e5 to your computer and use it in GitHub Desktop.
Save reasonstousegenesis/cfdec91f99f06516b6e5 to your computer and use it in GitHub Desktop.
Prevent posts appearing more than once across all loops on your site
<?php
// Paste the code BELOW this line into your child theme functions.
/**
* Prevent posts appearing more than once across all loops on your site
*
* @author Reasons to Use Genesis
* @link http://reasonstousegenesis.com/genesis-global-exclude/
*/
remove_action( 'genesis_after_entry', 'genesis_add_id_to_global_exclude' );
add_action( 'genesis_after_entry', 'rtug_add_id_to_global_exclude' );
function rtug_add_id_to_global_exclude() {
global $wp_query, $_genesis_displayed_ids;
$_genesis_displayed_ids[] = get_the_ID();
$wp_query->set( 'post__not_in', (array) $_genesis_displayed_ids );
}
<?php
// Paste the code BELOW this line into your child theme functions.
/**
* Prevent posts appearing more than once across all loops on your site (XHTML)
*
* @author Reasons to Use Genesis
* @link http://reasonstousegenesis.com/genesis-global-exclude/
*/
remove_action( 'genesis_after_post', 'genesis_add_id_to_global_exclude' );
add_action( 'genesis_after_post', 'rtug_add_id_to_global_exclude' );
function rtug_add_id_to_global_exclude() {
global $wp_query, $_genesis_displayed_ids;
$_genesis_displayed_ids[] = get_the_ID();
$wp_query->set( 'post__not_in', (array) $_genesis_displayed_ids );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment