• Hi,

    The Multiple Category Selection Widget is really cool. For my use case, I’m looking to be able to generate an RSS feed from the multiple category selection. As far as I can tell, the syntax to create a feed from any of a number of categories or excluding some categories is built into the core; however, the ability to say I want posts with category X and Y is not.

    In poking around, I created the following filter that allows me to pass a parameter in and activate the ‘AND’ logic

    15 function mcswrf_category_filter( $query ) {
     16    if( isset( $_REQUEST['MULTICATEGORY_OPERATOR'] ) && $_REQUEST['MULTICATEGORY_OPERATOR'] === 'AND' ){
     17       // the code below was leveraged from wp_includes/query.php
     18       $cat_and = array()
     19
     20       $cat_array = preg_split( '/[,\s]+/', urldecode( $query->get('cat') ) );
     21       $cat_array = array_map( 'intval', $cat_array );
     22       foreach ( $cat_array as $cat ) {
     23          if ( $cat > 0 ) {
     24             $cat_and[] = $cat;
     25          }
     26       }
     27       $query->set( 'category__and', $cat_and );
     28       unset( $cat_array, $cat_and );
     29    }
     30 }
     31 add_action( 'pre_get_posts', 'mcswrf_category_filter' );

    I’m thinking this could be easily added to the multiple category selection widget plus a hook to build an RSS link given the current state of the multiple category selection wiget so users would make their selection that use that setting for an rss feed.

    https://wordpress.org/plugins/multiple-category-selection-widget/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘RSS feed with AND category selection’ is closed to new replies.