get_var( $wpdb->prepare( "SELECT pm.post_id FROM {$wpdb->postmeta} pm JOIN {$wpdb->posts} p ON p.ID = pm.post_id WHERE pm.meta_key = 'seances' AND pm.meta_value = %s AND p.post_status = 'publish' LIMIT 1", (string) $seance_id ) ); } return $cache[ $seance_id ]; } /** * Lien public d'une séance : permalien du séminaire parent + #seance-{ID}, * ou permalien de la séance elle-même si aucun parent n'est trouvé. */ function thalim_get_seance_link( int $seance_id ): string { $parent_id = thalim_get_seance_parent_id( $seance_id ); return $parent_id ? get_permalink( $parent_id ) . '#seance-' . $seance_id : (string) get_permalink( $seance_id ); } // Séance de séminaire: redirect to parent séminaire with #seance-{ID} anchor add_action( 'template_redirect', function() { if ( ! is_single() ) return; if ( ! has_category( thalim_cat_id( 'seance' ) ) ) return; $seance_id = get_the_ID(); $parent_id = thalim_get_seance_parent_id( $seance_id ); if ( $parent_id ) { wp_redirect( get_permalink( $parent_id ) . '#seance-' . $seance_id, 301 ); exit; } } );