Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function filter_by_custom_fields( $query ) {
- $custom_fields = array(
- 'frame_height',
- // ...
- );
- $meta_query = array();
- foreach ( $custom_fields as $field ) {
- if ( ! isset( $_GET[ $field ] ) ) {
- continue;
- }
- $meta_query[] = array(
- 'key' => $field,
- 'value' => sanitize_text_field( $_GET[ $field ] ),
- 'compare' => 'LIKE',
- );
- }
- if ( $meta_query ) {
- $query->set( 'meta_query', $meta_query );
- }
- }
- add_action( 'pre_get_posts', 'filter_by_custom_fields' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement