Onchange the category dropdown display the feature post and blog list


I have three functions.

  1. The first one is displaying my categories dropdown from the custom post.
  2. The second is displaying the latest post(I have added the checkbox in each post if the user checked that then that will display in the latest post)
    3)And the third will display my all the post.

Below is the code I am using it.

//category dropdown
    function categoriesDropdown(){
    $categories = get_categories( array(
        'orderby' => 'name',
        'order'   => 'ASC',
        'taxonomy' => 'blogs_cat',
    ) );
    foreach( $categories as $category ) {
        $output.='<option value="'.$category->term_id.'">'.$category->name.'</option>'; 
        return $output;
    add_shortcode( 'showCategoryList', 'categoriesDropdown');
    // Feature blog if check box selected.
    function latestBlogView( $atts ){
          $the_query =array(
          'post_type' => 'blog',
          'post_status' => 'publish',
          'posts_per_page' => 3,
          'meta_key' => 'latestblog',
          'meta_value' => 1,
          'order'      => 'DESC'
        $postData = '';
        // The Loop
         $featured = new WP_Query($the_query);
        $postData.='<div class="latestBlogsWrapper articlesWrapper"><ul>';
        if ($featured->have_posts()): while($featured->have_posts()): $featured->the_post();
        $postData.= '<li><div class="grid-item"><a href="'.get_permalink($post->ID).'">
        <div class="blogBoxwrapper"> 
        <img src="'. get_the_post_thumbnail_url($post->ID, "full").'"> 
        <div class="blogCatname"><h5>'.get_the_title($post->ID).'</h5></div>
        endwhile; else:
        $postData.="Please select the feature post check box";
         $postData .= '</ul></div>';
        return $postData; 
    add_shortcode( 'latestblogs', 'latestBlogView');
    // Blog list
    function BlogView( $atts ){
        $args = array(  
            'post_type' => 'blog',
            'post_status' => 'publish',
            'posts_per_page' => 30, 
            'orderby' => 'title', 
            'order' => 'DESC', 
        );    $loop = new WP_Query( $args ); 
        $data ='';
        $data.='<div class="articlesWrapper"><ul>';
        while ( $loop->have_posts() ) : $loop->the_post(); 
            $tid = $loop->ID;
            $data.= ' 
                 <a href="'.get_permalink($tid).'">
                      <div class="blogBoxwrapper">
                         <img src="'.get_the_post_thumbnail_url($tid).'">
                            <div class="blogCatname">
        <div class="pt-5 text-center btnLoadmore"><a class="blogbtn blogbtnred loadMore" href="javascript:void(0);">Read More Blog Posts</a></div>
        return $data; 
    add_shortcode( 'blogandarticles', 'BlogView');

Now what I am doing is, When the user changes the category from the dropdown then I have to display the latest blog and blog list related to that category.

For example. On page load, I am displaying all the posts by default. Now I have a category called Movie in the dropdown. Once the user selects the Movie from the dropdown then I have to show the Movie related post in the latest blog and blog list.

Would you help me out with this issue?

user9437856 4 months 0 Answers 13 views 0

Leave an answer