Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
- }
- $page_id = 0;
- function exclude_specific_posts( $query ) {
- if ( $query->is_main_query() && $query->is_page() ) {
- $new_page_id = $query->get_queried_object_id();
- global $page_id;
- $page_id = $new_page_id;
- }
- if ( ! is_admin() && ( $query->is_home() || $query->is_category() || $query->is_search() ) ) {
- global $exclude_posts, $page_id;
- /* change the 61 value with your home page id */
- if ( $query->is_home() && 61 == $page_id ) {
- if ( ! empty( $query->query_vars['post__not_in'] ) ) {
- $excluded = array_unique( array_merge( $exclude_posts, $query->query_vars['post__not_in'] ) );
- $query->set( 'post__not_in', $excluded );
- } else {
- $query->set( 'post__not_in', $exclude_posts );
- }
- } elseif ( $query->is_category() || $query->is_search() ) {
- $query->set( 'post__not_in', $exclude_posts );
- }
- }
- }
- add_action( 'pre_get_posts', 'exclude_specific_posts', 99 );
- 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' );
- 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 );
- 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' );
- add_filter( 'exclude_post_popular_widget', 'exc_post_popular_widget' );
- function exc_post_popular_widget( $exc ) {
- global $exclude_posts;
- $exc = implode( ',', $exclude_posts );
- return $exc;
- }
- add_filter( 'jnews_ajax_attr_filters', 'exclude_in_ajax_module', 10, 2 );
- function exclude_in_ajax_module( $attr, $action ) {
- if ( 'jnews_module_ajax_jnews_block_4' == $action ) {
- global $exclude_posts;
- $exc = implode( ',', $exclude_posts );
- $attr['exclude_post'] .= ",{$exc}";
- }
- return $attr;
- }
- add_filter( 'jnews_get_content_attr', 'exclude_posts_in_author_page', 99, 3 );
- function exclude_posts_in_author_page( $attr, $page, $author ) {
- if ( 'jnews_author_' == $page ) {
- global $exclude_posts;
- $exc = implode( ',', $exclude_posts );
- $attr['exclude_post'] = $exc;
- }
- return $attr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement