Skip to content

Commit

Permalink
Fix issue with MultiplePostSelect firing error.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwelcher committed Jul 24, 2023
1 parent b542b05 commit c54e190
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/components/multiple-post-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@ export const MultiplePostSelect = ( { attributes, setAttributes } ) => {
const postTypes = useSelect( ( select ) =>
select( coreStore )
.getPostTypes()
.filter( ( { viewable } ) => viewable )
.map( ( { slug } ) => slug )
?.filter( ( { viewable } ) => viewable )
?.map( ( { slug } ) => slug )
);

if ( ! postTypes ) {
return (
<PanelBody
title={ __( 'Additional Post Types', 'advanced-query-loop' ) }
>
{ __( 'Loading…', 'advanced-query-loop' ) }
</PanelBody>
);
}
return (
<PanelBody
title={ __( 'Additional Post Types', 'advanced-query-loop' ) }
Expand All @@ -34,14 +43,14 @@ export const MultiplePostSelect = ( { attributes, setAttributes } ) => {
),
] }
suggestions={ [
...postTypes.filter( ( type ) => type !== postType ),
...postTypes?.filter( ( type ) => type !== postType ),
] }
onChange={ ( posts ) => {
// filter the tokens to remove wrong items.
setAttributes( {
query: {
...attributes.query,
multiple_posts: posts,
multiple_posts: posts || [],
},
} );
} }
Expand Down

0 comments on commit c54e190

Please sign in to comment.