I tried everything and nothing worked. ??
What I ended up doing (probably stupid) was modifying the class-page-posts.php.
I remarked out the bit that wasn’t working and added the following:
// new exclude posts with certain categories by id
if ( isset( $atts['exclude_category'] ) ) {
$exclude_category = explode( ',', $atts['exclude_category'] );
if ( isset( $this->args['cat'] ) ) {
$this->args['cat'] = array_merge( $this->args['cat'], $exclude_category );
} else {
$this->args['cat'] = $exclude_category;
}
}
This let me do it using categoty ids with “-” like wordpress does natively.
Don’t kill me.
I had to do something cuz I was on a deadline, but I would like to figure out why what was there didn’t work.
It DID work when I entered only one category but failed to filter by any category with 2 or more specified.
Does that help?
This is the section I remarked out:
// exclude posts with certain category by name (slug)
// if ( isset( $atts['exclude_category'] ) ) {
// $category = $atts['exclude_category'];
// if ( strpos( ',', $category ) ) {
// multiple
// $category = explode( ',', $category );
//
// foreach ( $category AS $cat ) {
// $term = get_category_by_slug( $cat );
// $exclude[] = '-' . $term->term_id;
// }
// $category = implode( ',', $exclude );
//
// } else {
// single
// $term = get_category_by_slug( $category );
// $category = '-' . $term->term_id;
// }
//
// if ( ! is_null( $this->args['cat'] ) ) {
// merge lists
// $this->args['cat'] .= ',' . $category;
// }
// $this->args['cat'] = $category;
// // unset our unneeded variables
// unset( $category, $term, $exclude );
// }
-
This reply was modified 6 years, 10 months ago by
Jon Hardison.