I have a crashing jQuery slider that i have been asked to fix. Currently it is loading 128 slides (causing crashed of course), but we only want to see 6.
I tried using jQuery to remove()
7th and higher li
elements, but the slider still loaded empty slides for those removed. I think the best solution is in the template code anyway.
These slides are pulled from posts who have a checkbox created from Advanced Custom Fields named "Featured Item". Asking or advising the client to uncheck the posts when they don't want them displayed is not an option.
Can you help me change the code to only pull the 6 most recent? Also, i would love to also have a script to uncheck that box right now for items 7 and above.
Thank you!
/*
* Template name: Blog Landing
*/
global $faar_opt, $wp_query;
$acf_fields = get_fields();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$categories = get_field('categories_of_blog', $post->id);
// pretty sure this is what i need to modify, as it has 'featured_item' (the checkbox)
$args = array(
'post_type' => 'post',
'posts_per_page' => 8,
'category__in' => $categories,
'meta_query' => array(
array(
'key' => 'featured_item',
'value' => '1'
)
),
);
$related_posts = new WP_Query($args);
$args = array(
'post_type' => 'post',
'posts_per_page' => 4,
'paged' => $paged,
'orderby' => 'date',
'category__in' => $categories
);
if(isset($wp_query->query_vars['blog_tag'])){
$args['tag'] = $wp_query->query_vars['blog_tag'];
$current_tag = get_term_by('slug', $wp_query->query_vars['blog_tag'], 'post_tag');
}
if(isset($wp_query->query_vars['blog_author'])){
$current_author = get_user_by('login', urldecode($wp_query->query_vars['blog_author']));
$args['author'] = $current_author->ID;
}
$all_posts = new WP_Query($args);
// each li is a slide, which is pulling 128, and needs to only be most recent 6
<ul class="slides blog-slides">
<?php
while($related_posts->have_posts()): $related_posts->the_post();
$author = get_user_by('id', $post->post_author);
?>
<li>
// slide content (removed for simplicity. Tell me if you need it.
</li>
<?php endwhile; wp_reset_query(); ?>
</ul>
$related_posts = new WP_Query($args);
line, set'posts_per_page' => 6,
and beloweul
tag replace all$related_posts->
to$all_posts->
.'orderby' => 'date'
), from newer to older.