Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion inc/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ function dsi_eventi_filters( $query ) {
*/
function dsi_schede_progetti_filters( WP_Query $query ) {

if ( ! is_admin() && $query->is_main_query() && (is_post_type_archive("scheda_progetto") || (get_queried_object()?->taxonomy ?? null) == "tipologia-progetto") ) {
if ( ! is_admin() && $query->is_main_query() && (is_post_type_archive("scheda_progetto") || (get_queried_object() && isset(get_queried_object()->taxonomy) && get_queried_object()->taxonomy == "tipologia-progetto")) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Segnalo che WP ha anche una funzione is_tax(), che è più compatta e "idiomatica" e svolge già tutti i controlli su get_queried_object().

Suggested change
if ( ! is_admin() && $query->is_main_query() && (is_post_type_archive("scheda_progetto") || (get_queried_object() && isset(get_queried_object()->taxonomy) && get_queried_object()->taxonomy == "tipologia-progetto")) ) {
if ( ! is_admin() && $query->is_main_query() && (is_post_type_archive("scheda_progetto") || is_tax("tipologia-progetto")) ) {

[v. #691]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qui si è modificata la linea precedente, in quanto la versione presente andava in conflitto con versioni di PHP precedenti all'8.0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sì, infatti: è l'operatore nullsafe ?->, che non è supportato.
Ma di tutta la sequenza delle verifiche su get_queried_object->taxonomy credo che se ne potrebbe fare a meno, perché quello è proprio il mestiere di is_tax().

//if ( ! is_admin() && $query->is_main_query() && (is_post_type_archive("scheda_progetto") || (get_queried_object()?->taxonomy ?? null) == "tipologia-progetto") ) {

$orderby = dsi_get_option("ordinamento_progetti", "didattica") ?? 'date';
$order_direction = dsi_get_option("direzione_ordinamento_progetti", "didattica") === 'asc' ? 'asc' : 'desc';
Expand Down
4 changes: 2 additions & 2 deletions inc/breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ protected function add_term_archive_items() {
if ( false !== $taxonomy->rewrite ) {

// If 'with_front' is true, dd $wp_rewrite->front to the trail.
if ( $taxonomy->rewrite['with_front'] && $wp_rewrite->front )
if ( array_key_exists('with_front', $taxonomy->rewrite) && $taxonomy->rewrite['with_front'] && $wp_rewrite->front )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se deve essere controllata l'esistenza, perché non semplicemente ! empty()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ci potrebbero essere dei casi in cui with_font non era valorizzata, ecco perche questo check in più

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sì; intendevo che ! empty($taxonomy->rewrite['with_front']) ha lo stesso effetto ed è più leggibile e conciso.

$this->add_rewrite_front_items();

// Get parent pages by path if they exist.
Expand Down Expand Up @@ -1112,7 +1112,7 @@ protected function get_post_types_by_slug( $slug ) {

foreach ( $post_types as $type ) {

if ( $slug === $type->has_archive || ( true === $type->has_archive && $slug === $type->rewrite['slug'] ) )
if ( $slug === $type->has_archive || ( true === $type->has_archive && is_array($type->rewrite) && isset($type->rewrite['slug']) && $slug === $type->rewrite['slug']))
Copy link
Contributor

@enrimk enrimk Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non è un'eventualità piuttosto remota?
Cioè, mi pare che rewrite['slug'] qui possa risultare non definito solo nel caso di un post_type con has_archive === true e rewrite === false contemporaneamente (con archivio, ma senza permalink). È così? È un caso che si verifica nell'app?

$return[] = $type;
}

Expand Down
23 changes: 23 additions & 0 deletions inc/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1231,4 +1231,27 @@ function dsi_get_progetti_in_luogo($luogo_id)

return $progetti;
}
}



if(!function_exists("get_page_by_title_new")){
function get_page_by_title_new( $page_title, $output = OBJECT, $post_type = 'page' ) {
$query = new WP_Query([
'post_type' => 'page',
'title' => $page_title,
'post_status' => 'publish', // Opzionale: solo pagine pubblicate
'posts_per_page' => 1, // Opzionale: limitare a un risultato
]);

$page = null;

if ($query->have_posts()) {
$query->the_post();
$page = get_post(); // Recupera l'oggetto del post corrente
wp_reset_postdata(); // Resetta i dati del loop di WordPress
}

return $page;
}
}