context['filterwell/queryId'] ) ) { return; } $qlf_query_id = (int) $block->context['filterwell/queryId']; $qlf_inherit = ! empty( $block->context['filterwell/inherit'] ); $qlf_prefix = FilterWell::prefix( $qlf_query_id, $qlf_inherit ); $qlf_request = FilterWell::get_request( $qlf_prefix ); $qlf_label = FilterWell::text( $attributes, 'label', __( 'Sort by', 'filterwell' ) ); $qlf_names = array( 'date-desc' => __( 'Newest', 'filterwell' ), 'date-asc' => __( 'Oldest', 'filterwell' ), 'modified-desc' => __( 'Recently updated', 'filterwell' ), 'title-asc' => __( 'Title (A-Z)', 'filterwell' ), 'title-desc' => __( 'Title (Z-A)', 'filterwell' ), 'comment_count-desc' => __( 'Most commented', 'filterwell' ), ); $qlf_custom = is_array( $attributes['optionLabels'] ?? null ) ? $attributes['optionLabels'] : array(); $qlf_options = array_values( array_intersect( (array) ( $attributes['options'] ?? array() ), array_keys( FilterWell::SORTS ) ) ); if ( ! $qlf_options ) { return; } // Orden propio del bucle (el de la plantilla o el configurado en el bloque). $qlf_default = FilterWell::default_sort( $qlf_query_id, $qlf_inherit ); $qlf_current = $qlf_request['order'] ? $qlf_request['order'] : $qlf_default; $qlf_choices = array(); if ( ! in_array( $qlf_default, $qlf_options, true ) ) { $qlf_choices[''] = FilterWell::text( $attributes, 'defaultLabel', __( 'Default', 'filterwell' ) ); } foreach ( $qlf_options as $qlf_key ) { $qlf_name = ! empty( $qlf_custom[ $qlf_key ] ) && is_string( $qlf_custom[ $qlf_key ] ) ? $qlf_custom[ $qlf_key ] : $qlf_names[ $qlf_key ]; $qlf_choices[ $qlf_key === $qlf_default ? '' : $qlf_key ] = $qlf_name; } $qlf_selected = $qlf_current === $qlf_default ? '' : $qlf_current; $qlf_id = wp_unique_id( 'qlf-sort-' ); $qlf_border = wp_style_engine_get_styles( array( 'border' => $attributes['style']['border'] ?? array() ) ); $qlf_classes = $attributes['borderColor'] ?? '' ? 'has-border-color has-' . sanitize_html_class( $attributes['borderColor'] ) . '-border-color' : ''; $qlf_wrapper = get_block_wrapper_attributes( array( 'data-qlf-instant' => 'true' ) ); ?>
>