Load Post with jQuery and sort them with buttons

//Load Post with jQuery and sort them with buttons

Load Post with jQuery and sort them with buttons

Code to insert on a page


I want…

eCom A Competitive Edge More Leads

Code to Insert in your function files





add_action( 'wp_ajax_my_getlatest', 'get_latestresults' );  
add_action('wp_ajax_nopriv_my_getlatest', 'get_latestresults');

          
function get_latestresults($sresult) {
                    global $wpdb;
    wp_reset_postdata();                   
           
                           
$args = array( 'posts_per_page' => 10   );

$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); 
	 
    
  $format = get_post_format($post->ID);
?>


 
ID)) || $hide_thumbnail ) { $thumb_class=' no-thumbnail'; } ?>
ID, 'video' ); if ( $video_url ) { //pexeto_print_video( $video_url, $img_size['width'] ); ?>
ID) && !$hide_thumbnail ) { ?>
ID ); $thumb = wp_get_attachment_image_src( $thumb_id, 'full' ); $alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true); ?> <?php echo esc_attr($alt); ?>

ID); ?>

post_content, '' ); if ( $ismore ) {?>
ID, 'post' ); } // PRINT POST TAGS if ( is_single() ) { the_tags( '' ); } ?>
posts} WHERE guid='$image_src'"; // $id = $wpdb->get_var($query); // return $id; } add_action('wp_head','pluginname_ajaxurl'); function pluginname_ajaxurl() { ?> 10, 'tax_query' => array( array( 'taxonomy' => 'post_tag', 'field' => 'slug', 'terms' => 'competitive-edge' ) ) ); $myposts = get_posts( $args ); foreach ( $myposts as $post ) : setup_postdata( $post ); $format = get_post_format($post->ID); ?>
ID)) || $hide_thumbnail ) { $thumb_class=' no-thumbnail'; } ?>
ID, 'video' ); if ( $video_url ) { //pexeto_print_video( $video_url, $img_size['width'] ); ?>
ID) && !$hide_thumbnail ) { ?>
ID ); $thumb = wp_get_attachment_image_src( $thumb_id, 'full' ); $alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true); ?> <?php echo esc_attr($alt); ?>

ID); ?>

post_content, '' ); if ( $ismore ) {?>
ID, 'post' ); } // PRINT POST TAGS if ( is_single() ) { the_tags( '' ); } ?>
posts} WHERE guid='$image_src'"; // $id = $wpdb->get_var($query); // return $id; } //////// End Competitive Edge //// StarteCom add_action( 'wp_ajax_my_getlatestecom', 'get_latestresultsecom' ); add_action('wp_ajax_nopriv_my_getlatestecom', 'get_latestresultsecom'); function get_latestresultsecom($sresult) { global $wpdb; wp_reset_postdata(); $args = array( 'posts_per_page' => 10, 'tax_query' => array( array( 'taxonomy' => 'post_tag', 'field' => 'slug', 'terms' => 'ecom' ) ) ); $myposts = get_posts( $args ); foreach ( $myposts as $post ) : setup_postdata( $post ); $format = get_post_format($post->ID); ?>
ID)) || $hide_thumbnail ) { $thumb_class=' no-thumbnail'; } ?>
ID, 'video' ); if ( $video_url ) { //pexeto_print_video( $video_url, $img_size['width'] ); ?>
ID) && !$hide_thumbnail ) { ?>
ID ); $thumb = wp_get_attachment_image_src( $thumb_id, 'full' ); $alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true); ?> <?php echo esc_attr($alt); ?>

ID); ?>

post_content, '' ); if ( $ismore ) {?>
ID, 'post' ); } // PRINT POST TAGS if ( is_single() ) { the_tags( '' ); } ?>
posts} WHERE guid='$image_src'"; // $id = $wpdb->get_var($query); // return $id; } //// leads add_action( 'wp_ajax_my_getlatestleads', 'get_latestresultsleads' ); add_action('wp_ajax_nopriv_my_getlatestleads', 'get_latestresultsleads'); function get_latestresultsleads($sresult) { global $wpdb; wp_reset_postdata(); $args = array( 'posts_per_page' => 10, 'tax_query' => array( array( 'taxonomy' => 'post_tag', 'field' => 'slug', 'terms' => 'leads' ) ) ); $myposts = get_posts( $args ); foreach ( $myposts as $post ) : setup_postdata( $post ); $format = get_post_format($post->ID); ?>
ID)) || $hide_thumbnail ) { $thumb_class=' no-thumbnail'; } ?>
ID, 'video' ); if ( $video_url ) { //pexeto_print_video( $video_url, $img_size['width'] ); ?>
ID) && !$hide_thumbnail ) { ?>
ID ); $thumb = wp_get_attachment_image_src( $thumb_id, 'full' ); $alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true); ?> <?php echo esc_attr($alt); ?>

ID); ?>

post_content, '' ); if ( $ismore ) {?>
ID, 'post' ); } // PRINT POST TAGS if ( is_single() ) { the_tags( '' ); } ?>
posts} WHERE guid='$image_src'"; // $id = $wpdb->get_var($query); // return $id; } ?>

Code to insert in a js file

jQuery(function() {

   var pagel = 1;
var data = {
  action: 'my_getlatest',
          page: pagel,


}

jQuery.post(ajaxurl, data,function(response) {  

     //console.log(response);
     
     jQuery('.blogspace').append(response);
   jQuery('#blog-masonry').masonry({
  columnWidth: 200,
  itemSelector: '#post'
});
   
   /// PEXETO.init.initSite();PEXETO.init.blogMasonry(3);
     //jQuery('.blogspace').parent().css( "background-color", "red" );

       ///jQuery( ".section > section-content > section-desc" ).last().css( "background-color", "red" );

}  );




  jQuery('.ecom').click(function(){
  
  
                 jQuery('.blogspace').html('');
   var pagel = 1;
var data = {
  action: 'my_getlatestecom',
          page: pagel,


}

jQuery.post(ajaxurl, data,function(response) {  

     console.log(response);
            console.log('ecom');  
                 
 var mediaItemContainer = jQuery( '#blog-masonry' ); 
      
mediaItemContainer.masonry( {
    columnWidth:  200,
    itemSelector: '#post'
} );
///jQuery( mediaItemContainer ).prepend( '
foo
' ); jQuery(mediaItemContainer ).prepend(response); jQuery( mediaItemContainer ).masonry( 'reloadItems' ); jQuery( mediaItemContainer ).masonry( 'layout' ); } ); }); jQuery('.edge').click(function(){ jQuery('.blogspace').html(''); var pagel = 1; var data = { action: 'my_getlatestedge', page: pagel, } jQuery.post(ajaxurl, data,function(response) { ///console.log(response); var mediaItemContainer = jQuery( '#blog-masonry' ); mediaItemContainer.masonry( { columnWidth: 200, itemSelector: '#post' } ); ///jQuery( mediaItemContainer ).prepend( '
foo
' ); jQuery(mediaItemContainer ).prepend(response); jQuery( mediaItemContainer ).masonry( 'reloadItems' ); jQuery( mediaItemContainer ).masonry( 'layout' ); } ); }); jQuery('.leads').click(function(){ jQuery('.blogspace').html(''); var pagel = 1; var data = { action: 'my_getlatestleads', page: pagel, } jQuery.post(ajaxurl, data,function(response) { //// console.log(response); console.log('leads'); var mediaItemContainer = jQuery( '#blog-masonry' ); mediaItemContainer.masonry( { columnWidth: 200, itemSelector: '#post' } ); ///jQuery( mediaItemContainer ).prepend( '
foo
' ); jQuery(mediaItemContainer ).prepend(response); jQuery( mediaItemContainer ).masonry( 'reloadItems' ); jQuery( mediaItemContainer ).masonry( 'layout' ); console.log('leads'); // PEXETO.init.initSite();PEXETO.init.blogMasonry(3); //jQuery('.blogspace').parent().css( "background-color", "red" ); ///jQuery( ".section > section-content > section-desc" ).last().css( "background-color", "red" ); } ); }); });
By | 2014-07-11T20:54:11+00:00 July 11th, 2014|Categories: Wordpress 101 Guide|0 Comments

About the Author:

Leave A Comment