Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Fetch IDs of sponsored posts to exclude from main and feed queries.
- */
- function get_sponsored_post_ids() {
- $args = array(
- 'post_type' => 'post',
- 'posts_per_page' => -1,
- 'fields' => 'ids',
- 'meta_query' => array(
- array(
- 'key' => 'jnews_single_post',
- 'value' => '"sponsored_post";s:1:"1";',
- 'compare' => 'LIKE',
- ),
- ),
- );
- $query = new WP_Query( $args );
- return $query->posts;
- }
- $exclude_posts = array();
- if ( ! is_admin() ) {
- $exclude_posts = get_sponsored_post_ids();
- }
- /**
- * Exclude sponsored posts from main and category queries.
- */
- function exclude_specific_posts( $query ) {
- if ( ! is_admin() && ( $query->is_front_page() || $query->is_category() ) ) {
- global $exclude_posts;
- $query->set( 'post__not_in', $exclude_posts );
- }
- }
- add_action( 'pre_get_posts', 'exclude_specific_posts' );
- /**
- * Exclude sponsored posts from RSS feed.
- */
- function exclude_specific_posts_from_feed( $query ) {
- if ( $query->is_feed() ) {
- global $exclude_posts;
- $query->set( 'post__not_in', $exclude_posts );
- }
- }
- add_action( 'pre_get_posts', 'exclude_specific_posts_from_feed' );
- /**
- * Disable comments RSS feed.
- */
- function disable_comments_rss() {
- global $wp_rewrite;
- $wp_rewrite->feeds = array_diff( $wp_rewrite->feeds, array( 'comments_rss2' ) );
- }
- add_action( 'init', 'disable_comments_rss', 1 );
- /**
- * Redirect comments RSS feed to homepage.
- */
- function redirect_comments_rss_to_homepage() {
- if ( is_comment_feed() ) {
- wp_redirect( home_url(), 301 );
- exit;
- }
- }
- add_action( 'template_redirect', 'redirect_comments_rss_to_homepage' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement