diff --git a/src/helpers/current-page-helper.php b/src/helpers/current-page-helper.php index 6109a77b932..28f6289925b 100644 --- a/src/helpers/current-page-helper.php +++ b/src/helpers/current-page-helper.php @@ -482,10 +482,12 @@ protected function get_non_cached_date_archive_permalink() { * @return int The amoumt of queried terms. */ protected function count_queried_terms() { - $wp_query = $this->wp_query_wrapper->get_main_query(); - $term = $wp_query->get_queried_object(); + $wp_query = $this->wp_query_wrapper->get_main_query(); + $term = $wp_query->get_queried_object(); + + $queried_terms = $wp_query->tax_query->queried_terms; - if ( empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { + if ( is_null( $term ) || empty( $queried_terms[ $term->taxonomy ]['terms'] ) ) { return 0; } diff --git a/src/presentations/indexable-term-archive-presentation.php b/src/presentations/indexable-term-archive-presentation.php index cd60880192f..460f83693d6 100644 --- a/src/presentations/indexable-term-archive-presentation.php +++ b/src/presentations/indexable-term-archive-presentation.php @@ -92,7 +92,7 @@ public function generate_meta_description() { * @return array The source. */ public function generate_source() { - if ( ! empty( $this->model->object_id ) ) { + if ( ! empty( $this->model->object_id ) || is_null( \get_queried_object() ) ) { return \get_term( $this->model->object_id, $this->model->object_sub_type ); } @@ -152,7 +152,7 @@ public function generate_robots() { * First we get the no index option for this taxonomy, because it can be overwritten the indexable value for * this specific term. */ - if ( ! $this->taxonomy->is_indexable( $this->source->taxonomy ) ) { + if ( is_wp_error( $this->source ) || ! $this->taxonomy->is_indexable( $this->source->taxonomy ) ) { $robots['index'] = 'noindex'; } @@ -176,6 +176,10 @@ public function generate_title() { return $this->model->title; } + if ( is_wp_error( $this->source ) ) { + return $this->model->title; + } + // Get the SEO title as entered in Search Appearance. $title = $this->options->get( 'title-tax-' . $this->source->taxonomy ); if ( $title ) { @@ -209,6 +213,10 @@ protected function is_multiple_terms_query() { return false; } + if ( is_wp_error( $this->source ) ) { + return false; + } + $queried_terms = $query->tax_query->queried_terms; if ( empty( $queried_terms[ $this->source->taxonomy ]['terms'] ) ) {