Add exclude parameters to latest_posts

This commit is contained in:
Tetrakern 2023-03-10 17:23:29 +01:00
parent 0db0ffd852
commit 29f834588e
4 changed files with 38 additions and 16 deletions

View File

@ -523,11 +523,13 @@ Renders a two-column grid of small cards, showing the latest four chapters order
### Latest Posts
Renders the last blog post or a list of blog posts, ignoring sticky posts, ordered by publishing date, descending. Optional parameters are **count**, **author**, **post_ids**, **categories**, **tags**, **rel**, and **class**.
Renders the last blog post or a list of blog posts, ignoring sticky posts, ordered by publishing date, descending. Optional parameters are **count**, **author**, **post_ids**, **exclude_cat_ids**, **exclude_tag_ids**, **categories**, **tags**, **rel**, and **class**.
* **count:** Limit posts to any positive number, although you should keep it reasonable. Default `1`.
* **author:** Only show posts of a specific author. Make sure to write the name right.
* **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.
* **categories:** Comma-separated list of category names (case-insensitive), if you want to pick from a curated pool.
* **tags:** Comma-separated list of tag names (case-insensitive), if you want to pick from a curated pool.
* **rel:** Relationship between different taxonomies, either `AND` or `OR`. Default `AND`.

View File

@ -538,10 +538,10 @@ Filters the query arguments in the `fictioneer_latest_chapters` shortcode. The o
* $post_status (string) `'publish'`
* $author_name (string|null) `$args['author']`
* $post__in (array) `$args['post_ids']`
* $meta_key (string) `'fictioneer_chapter_hidden'`
* $meta_value (int) `0`
* $category__not_in (array|null) `$args['excluded_cats']`
* $tag__not_in (array|null) `$args['excluded_tags']`
* $meta_key (string) `'fictioneer_chapter_hidden'`
* $meta_value (int) `0`
* $orderby (string) `$args['orderby']`
* $order (string) `$args['order']`
* $posts_per_page (int) `$args['count']`
@ -572,6 +572,8 @@ Filters the query arguments in the `fictioneer_latest_posts` shortcode. The opti
* $post_type (string) `'post'`
* $post_status (string) `'publish'`
* $post__in (array) `$args['post_ids']`
* $category__not_in (array|null) `$args['excluded_cats']`
* $tag__not_in (array|null) `$args['excluded_tags']`
* $author_name (string|null) `$args['author']`
* $has_password (boolean) `false`
* $orderby (string) `'date'`
@ -584,6 +586,8 @@ Filters the query arguments in the `fictioneer_latest_posts` shortcode. The opti
* $author (boolean|string) The author provided by the shortcode. Default `false`.
* $count (int) The number of posts provided by the shortcode. Default `1`.
* $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'`.
* $classes (\[string]) Array of additional CSS classes. Default empty.

View File

@ -639,13 +639,15 @@ add_shortcode( 'fictioneer_recommendation_cards', 'fictioneer_shortcode_latest_r
*
* @since 4.0
*
* @param string|null $attr['count'] Optional. Maximum number of items. Default 1.
* @param string|null $attr['author'] Optional. Limit items to a specific author.
* @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['rel'] Optional. Relationship between taxonomies. Default 'AND'.
* @param string|null $attr['class'] Optional. Additional CSS classes, separated by whitespace.
* @param string|null $attr['count'] Optional. Maximum number of items. Default 1.
* @param string|null $attr['author'] Optional. Limit items to a specific author.
* @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['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.
*/
@ -682,6 +684,8 @@ function fictioneer_shortcode_latest_posts( $attr ) {
'count' => $count,
'author' => $author,
'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,
'classes' => $classes

View File

@ -8,12 +8,14 @@
* @subpackage Fictioneer
* @since 4.0
*
* @internal $args['author'] The author provided by the shortcode. Default false.
* @internal $args['count'] The number of posts provided by the shortcode. Default 1.
* @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'] Array of additional CSS classes. Default empty.
* @internal $args['author'] The author provided by the shortcode. Default false.
* @internal $args['count'] The number of posts provided by the shortcode. Default 1.
* @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'] Array of additional CSS classes. Default empty.
*/
?>
@ -40,6 +42,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_latest_posts_query_args', $query_args, $args );