Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't render the post curation component if the selected post types doesn't support titles #104

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/components/post-include-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ export const PostIncludeControls = ( { attributes, setAttributes } ) => {
return <div>{ __( 'Loading…', 'advanced-query-loop' ) }</div>;
}

// If the first post in the posts array does not have a title, don't render the component.
if ( posts.length > 0 && ! posts[ 0 ].title ) {
return null;
}

return (
<>
<h2> { __( 'Include Posts', 'advanced-query-loop' ) }</h2>
Expand All @@ -101,7 +106,9 @@ export const PostIncludeControls = ( { attributes, setAttributes } ) => {
<FormTokenField
label={ __( 'Posts', 'advanced-query-loop' ) }
value={ includePosts.map( ( item ) => item.title ) }
suggestions={ posts.map( ( post ) => post.title.rendered ) }
suggestions={ posts.map(
( post ) => post?.title?.rendered
) } // Need to fix this here. Posts might not have title.rendered
onInputChange={ ( searchPost ) =>
setSearchArg( searchPost )
}
Expand Down
Loading