Add exclude parameters to showcase

This commit is contained in:
Tetrakern 2023-03-10 17:29:00 +01:00
parent 29f834588e
commit 2722512fd2
4 changed files with 46 additions and 24 deletions

View File

@ -669,7 +669,7 @@ Renders the search form with advanced options (if not disabled in the settings).
### Showcase
Renders dynamic grid of thumbnails with title, showing the latest eight posts of the specified type ordered by publishing date, descending. Requires **for** parameter. Optional parameters are **count**, **author**, **order**, **orderby**, **post_ids**, **no_cap**, and **class**. The thumbnail is either the **Landscape Image** or **Cover Image** (if available), with chapters defaulting to the parent story.
Renders dynamic grid of thumbnails with title, showing the latest eight posts of the specified type ordered by publishing date, descending. Requires **for** parameter. Optional parameters are **count**, **author**, **order**, **orderby**, **post_ids**, **exclude_cat_ids**, **exclude_tag_ids**, **no_cap**, and **class**. The thumbnail is either the **Landscape Image** or **Cover Image** (if available), with chapters defaulting to the parent story.
* **for:** Desired post type, either `stories`, `chapters`, `collections`, or `recommendations`.
* **count:** Limit posts to any positive number, although you should keep it reasonable. Default `8`.
@ -677,6 +677,8 @@ Renders dynamic grid of thumbnails with title, showing the latest eight posts of
* **order:** Either `desc` (descending) or `asc` (ascending). Default `desc`.
* **orderby:** The default is `date`, but you can also use `rand` and [more](https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters).
* **post_ids:** Comma-separated list of post IDs, if you want to pick from a curated pool.
* **exclude_cat_ids:** Comma-separated list of category IDs to exclude.
* **exclude_tag_ids:** Comma-separated list of tag IDs to exclude.
* **no_cap:** Set `true` if you want to hide the caption.
* **class:** Additional CSS classes, separated by whitespace.

View File

@ -691,6 +691,8 @@ Filters the query arguments in the `fictioneer_showcase` shortcode. The optional
* $post_status (string) `'publish'`
* $author_name (string|null) `$args['author']`
* $post__in (array) `$args['post_ids']`
* $category__not_in (array|null) `$args['excluded_cats']`
* $tag__not_in (array|null) `$args['excluded_tags']`
* $orderby (string) `$args['orderby']`
* $order (string) `$args['order']`
* $posts_per_page (int) `$args['count']`
@ -704,6 +706,8 @@ Filters the query arguments in the `fictioneer_showcase` shortcode. The optional
* $orderby (string) Optional. Default `'date'`.
* $order (string) Optional. Default `'desc'`.
* $post_ids (\[string]) Array of post IDs. Default empty.
* $excluded_cats (\[string]) Array of category IDs to exclude. Default empty.
* $excluded_tags (\[string]) Array of tag IDs to exclude. Default empty.
* $taxonomies (\[array]) Array of taxonomy arrays (names). Default empty.
* $relation (string) Relationship between taxonomies. Default `'AND'`.
* $no_cap (boolean) Whether to hide captions. Default `false`.

View File

@ -204,20 +204,22 @@ function fictioneer_get_shortcode_tax_query( $args ) {
*
* @since 5.0
*
* @param string $attr['for'] What the showcase is for. Allowed are chapters,
* collections, recommendations, and stories.
* @param string|null $attr['count'] Optional. Maximum number of items. Default 9.
* @param string|null $attr['author'] Optional. Limit items to a specific author.
* @param string|null $attr['order'] Optional. Order direction. Default 'DESC'.
* @param string|null $attr['orderby'] Optional. Order argument. Default 'date'.
* @param string|null $attr['post_ids'] Optional. Limit items to specific post IDs.
* @param string|null $attr['categories'] Optional. Limit items to specific category names.
* @param string|null $attr['tags'] Optional. Limit items to specific tag names.
* @param string|null $attr['fandoms'] Optional. Limit items to specific fandom names.
* @param string|null $attr['genres'] Optional. Limit items to specific genre names.
* @param string|null $attr['characters'] Optional. Limit items to specific character names.
* @param string|null $attr['rel'] Optional. Relationship between taxonomies. Default 'AND'.
* @param string|null $attr['class'] Optional. Additional CSS classes, separated by whitespace.
* @param string $attr['for'] What the showcase is for. Allowed are chapters,
* collections, recommendations, and stories.
* @param string|null $attr['count'] Optional. Maximum number of items. Default 9.
* @param string|null $attr['author'] Optional. Limit items to a specific author.
* @param string|null $attr['order'] Optional. Order direction. Default 'DESC'.
* @param string|null $attr['orderby'] Optional. Order argument. Default 'date'.
* @param string|null $attr['post_ids'] Optional. Limit items to specific post IDs.
* @param string|null $attr['exclude_tag_ids'] Optional. Exclude posts with these tags.
* @param string|null $attr['exclude_cat_ids'] Optional. Exclude posts with these categories.
* @param string|null $attr['categories'] Optional. Limit items to specific category names.
* @param string|null $attr['tags'] Optional. Limit items to specific tag names.
* @param string|null $attr['fandoms'] Optional. Limit items to specific fandom names.
* @param string|null $attr['genres'] Optional. Limit items to specific genre names.
* @param string|null $attr['characters'] Optional. Limit items to specific character names.
* @param string|null $attr['rel'] Optional. Relationship between taxonomies. Default 'AND'.
* @param string|null $attr['class'] Optional. Additional CSS classes, separated by whitespace.
*
* @return string The rendered shortcode HTML.
*/
@ -256,6 +258,8 @@ function fictioneer_shortcode_showcase( $attr ) {
'orderby' => $orderby,
'order' => $order,
'post_ids' => $post_ids,
'excluded_tags' => fictioneer_explode_list( $attr['exclude_tag_ids'] ?? '' ),
'excluded_cats' => fictioneer_explode_list( $attr['exclude_cat_ids'] ?? '' ),
'taxonomies' => fictioneer_get_shortcode_taxonomies( $attr ),
'relation' => $rel,
'no_cap' => $no_cap == 'true' || $no_cap == '1',

View File

@ -11,15 +11,17 @@
* @subpackage Fictioneer
* @since 4.0
*
* @internal $args['type'] Post type if the showcase.
* @internal $args['count'] Maximum number of items. Default 8.
* @internal $args['order'] Order direction. Default 'DESC'.
* @internal $args['orderby'] Order argument. Default 'date'.
* @internal $args['author'] Author provided by the shortcode.
* @internal $args['post_ids'] Array of post IDs. Default empty.
* @internal $args['taxonomies'] Array of taxonomy arrays. Default empty.
* @internal $args['relation'] Relationship between taxonomies.
* @internal $args['classes'] Additional classes.
* @internal $args['type'] Post type if the showcase.
* @internal $args['count'] Maximum number of items. Default 8.
* @internal $args['order'] Order direction. Default 'DESC'.
* @internal $args['orderby'] Order argument. Default 'date'.
* @internal $args['author'] Author provided by the shortcode.
* @internal $args['post_ids'] Array of post IDs. Default empty.
* @internal $args['excluded_cats'] Array of category IDs to exclude. Default empty.
* @internal $args['excluded_tags'] Array of tag IDs to exclude. Default empty.
* @internal $args['taxonomies'] Array of taxonomy arrays. Default empty.
* @internal $args['relation'] Relationship between taxonomies.
* @internal $args['classes'] Additional classes.
*/
?>
@ -45,6 +47,16 @@ if ( ! empty( $args['taxonomies'] ) ) {
$query_args['tax_query'] = fictioneer_get_shortcode_tax_query( $args );
}
// Excluded tags?
if ( ! empty( $args['excluded_tags'] ) ) {
$query_args['tag__not_in'] = $args['excluded_tags'];
}
// Excluded categories?
if ( ! empty( $args['excluded_cats'] ) ) {
$query_args['category__not_in'] = $args['excluded_cats'];
}
// Apply filters
$query_args = apply_filters( 'fictioneer_filter_shortcode_showcase_query_args', $query_args, $args );