Created
August 19, 2014 19:47
-
-
Save drrobotnik/ea9a03f6724a51345bad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'wp_ajax_tt_action', 'tt_action_callback' ); | |
add_action( 'wp_ajax_nopriv_tt_action', 'tt_action_callback' ); | |
function tt_action_callback() { | |
$args = $_POST['query_args']; | |
$args['posts_per_page'] = 10; | |
$args['post_status'] = 'publish'; | |
$args['suppress_filters'] = true; | |
$args['cache_results'] = false; | |
$filter = new WP_Query( $args ); // dumping query arg shows posts_per_page set to 10, but results are 26. | |
if ( $filter->have_posts() ) { | |
while ( $filter->have_posts() ) { $filter->the_post(); | |
if( turbotax_is_mobile() ) { | |
get_template_part( 'content-mobile' ); | |
} else { | |
get_template_part( 'content', get_post_format() ); | |
} | |
} | |
} else { | |
get_template_part( 'content', 'none' ); | |
} | |
die(); | |
} | |
add_action( 'wp_footer', 'tt_action_javascript' ); | |
function tt_action_javascript() { | |
?> | |
<script type="text/javascript" > | |
jQuery(document).ready(function($) { | |
$('.cat-filter a').on('click',function( event) { | |
event.preventDefault(); | |
var filter = ( $(this).parent().hasClass('filter-popular') ) ? 'comment_count' : 'date'; | |
infiniteScroll.settings.query_args.orderby = filter; | |
var data = { | |
'action': 'tt_action', | |
'query_args': infiniteScroll.settings.query_args | |
}; | |
var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>"; | |
$('#main').hide(); | |
$('#main article').remove(); | |
$.post( ajaxurl, data, function( response ) { | |
$('#main').prepend( response ).show(); | |
}); | |
}); | |
}); | |
</script> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment