Skip to content

Instantly share code, notes, and snippets.

@janisdonis
Created September 8, 2015 15:09
Show Gist options
  • Save janisdonis/91c981bad140479091ed to your computer and use it in GitHub Desktop.
Save janisdonis/91c981bad140479091ed to your computer and use it in GitHub Desktop.
Tax custom field
<?php
$args = array(
'post_type' => 'products',
'tax_query' => array(),
);
if(get_field('multi_filter') ) {
$temp = array();
while(has_sub_field('multi_filter')){
$_temp = array(
'taxonomy' => get_sub_field('taxonomy'),
'field' => 'slug',
'terms' => get_sub_field('term'),
'operator' => 'AND',
);
}
$args['tax_query'] = $_temp;
}
$query = new WP_Query( $args );
?>
@martins-giberts
Copy link

<?php 
$args = array(
    'post_type' => 'products',
    'tax_query' => array(
        'relation' => 'AND',
    ),
);

if(get_field('multi_filter') ) {
    while(has_sub_field('multi_filter')){
        $args['tax_query'][] = array(
            'taxonomy' => get_sub_field('taxonomy'),
            'field'    => 'slug',
            'terms'    => get_sub_field('term'),
            'operator' => 'AND',
        );
    }
}
$query = new WP_Query( $args );
?>

@janisdonis
Copy link
Author

'products', 'tax_query' => array( 'relation' => 'AND', ), ); ``` if(get_field('multi_filter') ) { while(has_sub_field('multi_filter')){ $args['tax_query'][] = array( 'taxonomy' => get_sub_field('taxonomy'), 'field' => 'slug', 'terms' => get_sub_field('term'), ); } } $query = new WP_Query( $args ); ?>
                        <?php if ( $query->have_posts() ) : ?>
                        <?php while ($query->have_posts() ) : $query->the_post(); ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment