Add taxonomies to showcase shortcode

This commit is contained in:
Tetrakern 2023-03-09 11:40:41 +01:00
parent abe9b117ab
commit cc21ef6178
3 changed files with 57 additions and 11 deletions

View File

@ -638,6 +638,34 @@ Filters the HTML for the search title before it is rendered in the `search.php`
---
### `apply_filters( 'fictioneer_filter_showcase_query_args', $query_args, $args )`
Filters the query arguments in the `fictioneer_showcase` shortcode. The optional taxonomy arrays can include categories, tags, fandoms, genres, and characters.
**$query_args:**
* $post_type (string) `$args['type']`
* $post_status (string) `'publish'`
* $author_name (string|null) `$args['author']`
* $post__in (array) `$args['post_ids']`
* $orderby (string) `$args['orderby']`
* $order (string) `$args['order']`
* $posts_per_page (int) `$args['count']`
* $update_post_term_cache (boolean) `false`
* $no_found_rows (boolean) `true`
**$args:**
* $type (string) Either `'fcn_collection'`, `'fcn_story'`, `'fcn_chapter'`, or `'fcn_recommendation'`.
* $author (boolean|string) The author provided by the shortcode. Default `false`.
* $count (int) The number of posts provided by the shortcode. Default `1`.
* $orderby (string) Optional. Default `'date'`.
* $order (string) Optional. Default `'desc'`.
* $post_ids (\[string]) Array of post IDs. 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`.
* $classes (\[string]) Array of additional CSS classes. Default empty.
---
### `apply_filters( 'fictioneer_filter_stories_card_args', $card_args, $args )`
Filters the arguments passed to the `partials/_card-story` template part in the `fictioneer_stories_list( $args )` function, normally added via the `fictioneer_stories_after_content` hook.

View File

@ -227,12 +227,17 @@ function fictioneer_shortcode_showcase( $attr ) {
$orderby = $attr['orderby'] ?? 'date';
$no_cap = $attr['no_cap'] ?? false;
$post_ids = [];
$rel = 'AND';
$classes = [];
// Post IDs
if ( ! empty( $attr['posts'] ) ) {
$post_ids = str_replace( ' ', '', $attr['posts'] );
$post_ids = explode( ',', $post_ids );
$post_ids = is_array( $post_ids ) ? $post_ids : [];
$post_ids = fictioneer_explode_list( $attr['posts'] );
}
// Relation
if ( ! empty( $attr['rel'] ) ) {
$rel = strtolower( $attr['rel'] ) == 'or' ? 'OR' : $rel;
}
// Extra classes
@ -245,6 +250,8 @@ function fictioneer_shortcode_showcase( $attr ) {
'orderby' => $orderby,
'order' => $order,
'post_ids' => $post_ids,
'taxonomies' => fictioneer_get_shortcode_taxonomies( $attr ),
'relation' => $rel,
'no_cap' => $no_cap == 'true' || $no_cap == '1',
'classes' => $classes
);

View File

@ -11,13 +11,15 @@
* @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'] Limit query to specific author. Default none.
* @internal $args['post_ids'] Limit items to specific post IDs. Default empty array.
* @internal $args['class'] 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['taxonomies'] Array of taxonomy arrays. Default empty.
* @internal $args['relation'] Relationship between taxonomies.
* @internal $args['classes'] Additional classes.
*/
?>
@ -31,12 +33,21 @@ $query_args = array (
'order' => $args['order'] ?? 'DESC',
'orderby' => $args['orderby'] ?? 'date',
'posts_per_page' => $args['count'] ?? 8,
'update_post_term_cache' => false
'update_post_term_cache' => false,
'no_found_rows' => true
);
// Filter for author?
if ( isset( $args['author'] ) && $args['author'] ) $query_args['author_name'] = $args['author'];
// Taxonomies?
if ( ! empty( $args['taxonomies'] ) ) {
$query_args['tax_query'] = fictioneer_get_shortcode_tax_query( $args );
}
// Apply filters
$query_args = apply_filters( 'fictioneer_filter_showcase_query_args', $query_args, $args );
// Query collections
$query = new WP_Query( $query_args );