WordPress.org

Making WordPress.org


Ignore:
Timestamp:
04/12/2016 09:39:42 PM (4 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Change search form behavior to default checkboxes to be unchecked.

  • When a search is performed with no checkboxes checked, search all parsed post types (same as if all checkboxes checked).
  • Makes it easier to filter search by only necessitating clicking checkbox(es) to limit search, rather than unchecking checkbox(es).

Props keesiemeijer.
Fixes #1517.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/searchform.php

    r2286 r2939  
    5252                    'wp-parser-method'   => __( 'Methods',   'wporg' ),
    5353                );
     54               
     55                $qv_post_type = array_filter( (array) get_query_var( 'post_type' ) );   
     56
     57                if ( ! is_search() || in_array( 'any', $qv_post_type ) ) {
     58                    // no filters used
     59                    $qv_post_type = array();
     60                }
     61                       
    5462                foreach ( $search_post_types as $post_type => $label ) {
    55                     $qv_post_type = (array) get_query_var( 'post_type' );
     63                    $checked = checked( in_array( $post_type, $qv_post_type ), true, false );
    5664                ?>
    57                     <label><input type="checkbox" name="post_type[]" value="<?php echo esc_attr( $post_type ); ?>"
    58                     <?php checked( ! is_search() || in_array( 'any', $qv_post_type ) || in_array( $post_type, $qv_post_type ) ); ?> /> <?php echo $label; ?></label>
    59                 <?php } ?>
     65                        <label><input type="checkbox" name="post_type[]" value="<?php echo esc_attr( $post_type ); ?>"
     66                        <?php echo $checked; ?> /> <?php echo $label; ?></label>
     67            <?php } ?>
    6068        </div>
    6169    </form>
Note: See TracChangeset for help on using the changeset viewer.