پرش به محتویات

"Filter: bricks/filter_element/populated_options"

فیلتر PHPbricks/filter_element/populated_options به شما امکان می‌دهد تا گزینه‌های جمع‌شده فیلتر - انتخاب، فیلتر - رادیو و فیلتر - چک باکس را قبل از اینکه به HTML ارائه شوند، تغییر دهید. (@since 2.0.2)

این مفید است اگر می‌خواهید:

  • افزودن/حذف گزینه‌های خاصی
  • گزینه‌های سفارش مجدد (بر اساس نیاز سفارشی پیچیده)
  • متن یا مقادیر نمایش را تغییر دهید

مثال:

مثال زیر گزینه "بیوگرافی" را از یک المان فیلتر با شناسه uzehuy حذف می‌کند:

/**
 * $options is an array of options that are populated by the element
 * 'value' is the value of the option
 * 'text' is the display text of the option
 * 'is_all' exists and is true if the option is the "All" option
 * 'is_placeholder' exist and is true if the option is a placeholder option
 */
add_filter( 'bricks/filter_element/populated_options', function( $options, $element ) {
  if ( $element->id === 'uzehuy' ) {
    // Remove the options that value is 'biography'
    $options = array_filter( $options, function( $option ) {
      return $option['value'] !== 'biography';
    } );
  }

  return $options;
}, 10, 2 );