-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from ryanwelcher/feature/children-of-current-item
Show children of current item only
- Loading branch information
Showing
8 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* Post Parent Processing | ||
*/ | ||
|
||
namespace AdvancedQueryLoop\Traits; | ||
|
||
/** | ||
* Trait | ||
*/ | ||
trait Post_Parent { | ||
|
||
/** | ||
* Main processing function. | ||
*/ | ||
public function process_post_parent(): void { | ||
$parent = $this->custom_params['post_parent']; | ||
|
||
if ( $this->is_post_id( $parent ) ) { | ||
$this->custom_args['post_parent'] = $parent; | ||
} else { | ||
// This is usually when this was set on a template. | ||
global $post; | ||
$this->custom_args['post_parent'] = $post->ID; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { ToggleControl } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { store as editorStore } from '@wordpress/editor'; | ||
|
||
export const ChildItemsToggle = ( { attributes, setAttributes } ) => { | ||
const { query: { post_parent: postParent } = {} } = attributes; | ||
|
||
const { isHierarchial, postTypeName, postID } = useSelect( ( select ) => { | ||
const post = select( editorStore ).getCurrentPost(); | ||
const postType = select( editorStore ).getCurrentPostType(); | ||
const postTypeObject = select( coreStore ).getPostType( postType ); | ||
|
||
return { | ||
isHierarchial: postTypeObject?.hierarchical, | ||
postTypeName: postType, | ||
postID: post?.id, | ||
}; | ||
}, [] ); | ||
|
||
return ( | ||
<ToggleControl | ||
__nextHasNoMarginBottom | ||
label={ __( 'Show child items only', 'advanced-query-loop' ) } | ||
help={ __( | ||
'Only show child items of this item. This option is only available for hierarchical post types such as pages.', | ||
'advanced-query-loop' | ||
) } | ||
disabled={ ! isHierarchial && postTypeName !== 'wp_template' } | ||
checked={ !! postParent } | ||
onChange={ ( value ) => | ||
setAttributes( { | ||
query: { | ||
...attributes.query, | ||
post_parent: value ? postID : 0, | ||
}, | ||
} ) | ||
} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters