drrobotnik
8/19/2014 - 7:47 PM

gistfile1.txt

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
}