Alphabet.php
9 months ago
ColumnGap.php
9 months ago
ColumnWidth.php
9 months ago
Columns.php
9 months ago
ExcludePosts.php
9 months ago
ExcludeTerms.php
9 months ago
HideEmptyTerms.php
9 months ago
HideEmpty_Deprecated.php
9 months ago
InstanceId.php
9 months ago
ParentPost.php
9 months ago
ParentTermCommon.php
9 months ago
ParentTermId.php
9 months ago
ParentTermSlugOrId.php
9 months ago
PostType.php
9 months ago
PostsTerms.php
9 months ago
SymbolsFirst.php
9 months ago
Taxonomy.php
9 months ago
TermsCommon.php
9 months ago
TermsTerms.php
9 months ago
ParentTermCommon.php
58 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Parent Term Query Part. |
| 4 | * |
| 5 | * @package alphalisting |
| 6 | */ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace eslin87\AlphaListing\Shortcode\QueryParts; |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; |
| 14 | } |
| 15 | |
| 16 | use \eslin87\AlphaListing\Shortcode\Extension; |
| 17 | |
| 18 | /** |
| 19 | * Parent Term Common implementation. |
| 20 | */ |
| 21 | abstract class ParentTermCommon extends Extension { |
| 22 | /** |
| 23 | * The types of listing this shortcode extension may be used with. |
| 24 | * |
| 25 | * @since 4.0.0 |
| 26 | * @var array<string|int> |
| 27 | */ |
| 28 | public $display_types = array( 'terms' ); |
| 29 | |
| 30 | /** |
| 31 | * Update the query with this extension's additional configuration. |
| 32 | * |
| 33 | * @param \AlphaListing\Query $query The query. |
| 34 | * @param int $parent_id The shortcode attribute value. |
| 35 | * @param array $attributes The complete set of shortcode attributes. |
| 36 | * @return mixed The updated query. |
| 37 | */ |
| 38 | public function shortcode_query_with_parent_id( $query, int $parent_id, array $attributes ) { |
| 39 | if ( isset( $attributes['get-all-children'] ) && alphalisting_is_truthy( $attributes['get-all-children'] ) ) { |
| 40 | $parent_selector = 'child_of'; |
| 41 | } else { |
| 42 | $parent_selector = 'parent'; |
| 43 | } |
| 44 | |
| 45 | if ( -1 < $parent_id ) { |
| 46 | $query = wp_parse_args( |
| 47 | $query, |
| 48 | array( $parent_selector => $parent_id ) |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | return $query; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | |
| 57 | |
| 58 |