Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ( ! function_exists( 'exclude_terms_from_next_post' ) ) {
- /**
- * Exclude terms from the prev-next post query.
- *
- * This function modifies the prev-next post query to exclude posts that share
- * any of the terms.
- *
- * @param array $excluded_terms Array of term IDs to exclude.
- *
- * @return array Modified array of excluded term IDs.
- */
- function exclude_terms_from_next_post( $excluded_terms ) {
- if ( empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) {
- $excluded_terms = array();
- }
- /**
- * List Categoory Slugs to Exclude
- */
- $terms = array(
- 'jnews_demo_education',
- 'jnews_demo_editorial',
- );
- foreach ( $terms as $term ) {
- /**
- * Get the term object by slug
- * This assumes that the terms are categories.
- * If they are not, you may need to adjust this accordingly.
- */
- $category = get_term_by( 'slug', $term, 'category' );
- /**
- * Add each term ID to the excluded terms array
- */
- $excluded_terms[] = $category->term_id;
- }
- return $excluded_terms;
- }
- add_filter( 'get_previous_post_excluded_terms', 'exclude_terms_from_next_post' );
- add_filter( 'get_next_post_excluded_terms', 'exclude_terms_from_next_post' );
- }
Advertisement
Add Comment
Please, Sign In to add comment