Skip to content

Commit 2ce77d4

Browse files
authored
Merge pull request #104 from ryanwelcher/fix/posts-types-no-title
Don't render the post curation component if the selected post types doesn't support titles
2 parents ef1a636 + 660080f commit 2ce77d4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/components/post-include-controls.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ export const PostIncludeControls = ( { attributes, setAttributes } ) => {
8888
return <div>{ __( 'Loading…', 'advanced-query-loop' ) }</div>;
8989
}
9090

91+
// If the first post in the posts array does not have a title, don't render the component.
92+
if ( posts.length > 0 && ! posts[ 0 ].title ) {
93+
return null;
94+
}
95+
9196
return (
9297
<>
9398
<h2> { __( 'Include Posts', 'advanced-query-loop' ) }</h2>
@@ -101,7 +106,9 @@ export const PostIncludeControls = ( { attributes, setAttributes } ) => {
101106
<FormTokenField
102107
label={ __( 'Posts', 'advanced-query-loop' ) }
103108
value={ includePosts.map( ( item ) => item.title ) }
104-
suggestions={ posts.map( ( post ) => post.title.rendered ) }
109+
suggestions={ posts.map(
110+
( post ) => post?.title?.rendered
111+
) } // Need to fix this here. Posts might not have title.rendered
105112
onInputChange={ ( searchPost ) =>
106113
setSearchArg( searchPost )
107114
}

0 commit comments

Comments
 (0)