WordPress Ajax filter: Create two loops for different output styles?

I have two different pages, with filters. Those two pages, have different layouts and styles.

I have three different filters for one page, where the output and style is the same.

For the “newsfilter” I need a different style. So I guess I need another loop?

How do I output two different loops? My current functions.php is:

function misha_filter_function(){
$args = array(
‘orderby’ => ‘date’, // we will sort posts by date
‘order’ => $_POST[‘date’] // ASC или DESC
);

$args = array(
‘tax_query’ => array(
‘relation’ => ‘AND’,
array(
‘taxonomy’ => ‘post_tag’,
‘field’ => $cat_id,
‘terms’ => $_POST[‘ownerfilter’],
),
array(
‘taxonomy’ => ‘post_tag’,
‘field’ => $cat_id,
‘terms’ => $_POST[‘locationfilter’],
),
)
);

$args = array(
‘tax_query’ => array(
‘relation’ => ‘AND’,
array(
‘taxonomy’ => ‘post_tag’,
‘field’ => $cat_id,
‘terms’ => $_POST[‘newsfilter’],
),
)
);

$relation = ‘AND’;
if( isset( $_POST[‘timefilter’] ) )
$args[‘tax_query’] = array(
‘relation’ => $relation,
array(
‘taxonomy’ => ‘post_tag’,
‘field’ => $cat_id,
‘terms’ => $_POST[‘timefilter’]
),
);

$query = new WP_Query( $args );

if( $query->have_posts() ) :
while( $query->have_posts() ): $query->the_post(); ?>
<!– post –>
<a href=”<?php the_permalink()?>”>
<div class=”col-md-3 col-sm-6 ver-item”>
<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘full’ );?>
<div class=”thumb” style=”background-image:url(‘<?php echo $thumb[‘0′];?>’);”></div>
<section>
<time><?php echo get_the_date();?></time>
<h3><?php the_title();?></h3>
<span><!– underline –></span>
</section>
</div>
</a>

<?php endwhile;
wp_reset_postdata(); else :
echo ‘Geen resultaten, probeer het opnieuw.’;
endif;
die();
}

add_action(‘wp_ajax_myfilter’, ‘misha_filter_function’);
add_action(‘wp_ajax_nopriv_myfilter’, ‘misha_filter_function’);

The filter results of the “newsfilter” need to get a different output and style. How can I do that?

Thanks in advance,

Thomas.

I’ve tried changing the $args to another name, that didn’t work. I’ve also tried adding a complete new function (news_filter_functions instead of misha_filter_function).

Read more here:: WordPress Ajax filter: Create two loops for different output styles?

Leave a Reply

Your email address will not be published. Required fields are marked *