get post based on category chosen in drop down – The ajax method

<div class=”latest_video”>
<?php wp_dropdown_categories(); ?>
<?php
// the query
$the_query = new WP_Query( array(
‘post_type’ => ‘post’,
‘posts_per_page’ => 10,
‘post_status’ => ‘publish’,
‘category_name’ => $_REQUEST[‘cat’]
) );
?>
<?php if ( $the_query->have_posts() ) : ?>
<!– the loop –>
<ul class=”flex”>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li class=”thebox”>
<div class=”theimg”><?php the_post_thumbnail( ‘large’) ?></div>
<div class=”stext3″>
<h4><?php $categories = get_the_category();
if ( ! empty( $categories ) ) {
echo ‘<a class=”themecolor” href=”‘ . esc_url( get_category_link( $categories[0]->term_id ) ) . ‘”>’ . esc_html( $categories[0]->name ) . ‘</a>’;
} ?></h4>
<h3><a href=”<?php the_permalink(); ?>” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a></h3>
</div>
</li>
<?php endwhile; ?>
</ul>
<!– end of the loop –>
<!– <?php wp_reset_postdata(); ?> –>
<?php endif; ?>
</div>

Now here onwards I am clueless How to make it work based on categories selected from the drop-down. Can someone help me to take things further or perhaps guide me how to start?

Read more here:: get post based on category chosen in drop down – The ajax method

Leave a Reply

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