• Resolved Ahni

    (@ahni)


    Hi. Is there a way to choose which categories I want to include in the feed? I only want to include one particular category.

    Thanks for the great plugin!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author OzTheGreat

    (@ozthegreat)

    Hi @ahni,

    Yep absolutely, if you add something like the code below to your theme’s functions.php then simply change the 5 to whatever the ID of the category is you wish to restrict it to.

    
    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 );
    

    Thanks

    Plugin Author OzTheGreat

    (@ozthegreat)

    Going to assume this did the job, let me know if not.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Limit feed to one category’ is closed to new replies.