diff --git a/packages/edit-site/src/components/page-patterns/index.js b/packages/edit-site/src/components/page-patterns/index.js index be3bb7429c32f9..69ebf66093806a 100644 --- a/packages/edit-site/src/components/page-patterns/index.js +++ b/packages/edit-site/src/components/page-patterns/index.js @@ -78,6 +78,7 @@ export default function DataviewsPatterns() { const categoryId = categoryIdFromURL || PATTERN_DEFAULT_CATEGORY; const [ view, setView ] = useState( DEFAULT_VIEW ); const previousCategoryId = usePrevious( categoryId ); + const previousPostType = usePrevious( type ); const viewSyncStatus = view.filters?.find( ( { field } ) => field === 'sync-status' )?.value; @@ -121,10 +122,10 @@ export default function DataviewsPatterns() { // Reset the page number when the category changes. useEffect( () => { - if ( previousCategoryId !== categoryId ) { + if ( previousCategoryId !== categoryId || previousPostType !== type ) { setView( ( prevView ) => ( { ...prevView, page: 1 } ) ); } - }, [ categoryId, previousCategoryId ] ); + }, [ categoryId, previousCategoryId, previousPostType, type ] ); const { data, paginationInfo } = useMemo( () => { // Search is managed server-side as well as filters for patterns. // However, the author filter in template parts is done client-side.