Our products presented with the model “WE SHOW … YOU SELL”
Per candidarsi o ricevere informazioni sulla nostra presentazione personalizzata.
// Aggiungi questo nel functions.php del tema child o in uno snippet plugin
function elementor_query_related_posts( $query ) {
// Nome del campo ACF: cambialo con il tuo
$acf_field_name = '
dettaglio_finiture_news';
// Prendi il campo per il post corrente
$post_id = get_the_ID();
if ( ! $post_id ) {
// Se non siamo in un contesto di singolo post, esci impostando query vuota
$query->set( 'post__in', array(0) );
return;
}
$related = get_field( $acf_field_name, $post_id );
if ( empty( $related ) ) {
// Nessun correlato: nessun risultato
$query->set( 'post__in', array(0) );
return;
}
// Normalizza in array di ID
$ids = array();
// Se ACF ritorna un array di numeri (IDs)
if ( is_array( $related ) && isset( $related[0] ) && is_numeric( $related[0] ) ) {
$ids = array_map( 'intval', $related );
} else {
// Se ACF ritorna Post Object(s)
if ( is_array( $related ) ) {
foreach ( $related as $r ) {
if ( is_object( $r ) && isset( $r->ID ) ) {
$ids[] = $r->ID;
} elseif ( is_array( $r ) && isset( $r['ID'] ) ) {
$ids[] = intval( $r['ID'] );
}
}
} else {
// singolo oggetto/ID
if ( is_object( $related ) && isset( $related->ID ) ) {
$ids[] = $related->ID;
} elseif ( is_numeric( $related ) ) {
$ids[] = intval( $related );
}
}
}
if ( empty( $ids ) ) {
$query->set( 'post__in', array(0) );
return;
}
// Imposta la query di Elementor: limita ai post specificati e mantieni l'ordine dei campi Relationship
$query->set( 'post__in', $ids );
$query->set( 'orderby', 'post__in' );
// numero di elementi: -1 = tutti, oppure imposta un numero
$query->set( 'posts_per_page', -1 );
}
add_action( 'elementor/query/related_posts', 'elementor_query_related_posts' );