Last active
August 8, 2017 09:11
-
-
Save ozthegreat/6da506fbed61effbcf0aeff18bdda987 to your computer and use it in GitHub Desktop.
Restrict Instant Articles RSS Feed by category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! function_exists( 'wpna_restrict_feed_author' ) ) : | |
/** | |
* Modifies the main RSS query. | |
* | |
* @param WP_Query $query | |
* @return $query | |
*/ | |
function wpna_restrict_feed_author( $query ) { | |
// Requested option name, / value to default to. | |
if ( function_exists( 'wpna_get_option' ) ) { | |
// get the feed slug. | |
$feed_slug = wpna_get_option( 'fbia_feed_slug' ); | |
// If it's the Instant Articles feed | |
if ( $query->is_feed( $feed_slug ) && $query->is_main_query() ) { | |
// Restrict to only show posts with this author ID. | |
$query->set( 'author', '3' ); | |
} | |
} | |
return $query; | |
} | |
endif; | |
add_filter( 'pre_get_posts', 'wpna_restrict_feed_author', 11, 1 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! function_exists( 'wpna_restrict_feed_category' ) ) : | |
/** | |
* Modifies the main RSS query. | |
* | |
* @param WP_Query $query | |
* @return $query | |
*/ | |
function wpna_restrict_feed_category( $query ) { | |
// Requested option name, / value to default to. | |
if ( function_exists( 'wpna_get_option' ) ) { | |
// get the feed slug. | |
$feed_slug = wpna_get_option( 'fbia_feed_slug' ); | |
// If it's the Instant Articles feed | |
if ( $query->is_feed( $feed_slug ) && $query->is_main_query() ) { | |
// Restrict to only show posts in a certain category. | |
$query->set( 'cat', 5 ); | |
} | |
} | |
return $query; | |
} | |
endif; | |
add_filter( 'pre_get_posts', 'wpna_restrict_feed_category', 11, 1 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! function_exists( 'wpna_restrict_feed_tag' ) ) : | |
/** | |
* Modifies the main RSS query. | |
* | |
* @param WP_Query $query | |
* @return $query | |
*/ | |
function wpna_restrict_feed_tag( $query ) { | |
// Requested option name, / value to default to. | |
if ( function_exists( 'wpna_get_option' ) ) { | |
// get the feed slug. | |
$feed_slug = wpna_get_option( 'fbia_feed_slug' ); | |
// If it's the Instant Articles feed | |
if ( $query->is_feed( $feed_slug ) && $query->is_main_query() ) { | |
// Restrict to only show posts with this tag. | |
$query->set( 'tag', 'action' ); | |
} | |
} | |
return $query; | |
} | |
endif; | |
add_filter( 'pre_get_posts', 'wpna_restrict_feed_tag', 11, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment