wordpress - Select a post from select box and display its featured image -


i have post select box , want display featured image of post while selecting post select box.something select post select box , display featured image of post below.

http://prntscr.com/d5e3ad custom js file code is

var $ = jquery; $(document).ready(function(){ $("post-thumb").css("display", "none"); $("#vzxms-post-slct").on('change', function(e){     e.preventdefault();     $slct_val = $("#vzxms-post-slct").val();     console.log($slct_val);     $.ajax({         url: ajaxurl,         data: $slct_val,         success: function(data){             $("#post-thumb").css("display", "block");         }     });  }); }); 

and plugin index file form in div wrap

<form method="post" action="">             <div class="form-group-field">                 <div class="left_label"><label>                     select post                 </label></div>                 <div class="rigth_input">                     <select id="vzxms-post-slct" name="vzxms-post-slct" class="vzxms-post-slct">                         <option selected="selected"> select post </option>                         <?php                         $args = array( 'post_type'=>'post');                         $myposts = get_posts( $args );                         foreach ( $myposts $post ) : setup_postdata( $post ); ?>                             <option value="<?php the_id();?>"><?php the_title(); ?></option>                         <?php endforeach;                          wp_reset_postdata();?>                     </select>   <!-- , here want show image -->                     <?php                      $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'post');                      ?>                     <img src="<?php echo $thumb[0]; ?>" id="post-thumb"/>                 </div>             </div>         </form> 

in select box option can loop through posts title below:

  <select >     <?php     $args = array( 'post_type'=>'post');     $myposts = get_posts( $args );     foreach ( $myposts $post ) : setup_postdata( $post ); ?>         <option value="<?php the_id();?>"><?php the_title(); ?></option>     <?php endforeach;      wp_reset_postdata();?>     </select> 

make ajax call on change of select option fetch post thumbnail post id

$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'post');  //thumbnail link echo $thumb[0]; 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -