A slider is created using PHP and WordPress.There are total of 8 slides. By default,the 8 latest posts are shown in sequence in the slider. When I post a new let say Sport news for today, it replaces the old news which was in position 1.The issue is, I want to Stick/pin an old news in a certain position e.g. position 1, So, whenever there is a new post published. It should skip the position 1 and go to position 2, if there is another post pinned at position 2, then It should go next position.
The pinned posts can start at any position and I wanting pinned posts to remain at their original location. For example if I have posts 2, and 6 as pinned posts, then I should have this [1,2,3,4,5,6]. After adding one I should get this one [7,2,1,3,4,6,5]. However, the current code groups the pinned posts at the beginning which leads to[2,6,7,1,3,4,5].
Looking forward for your help.
if ($pageposts):
global $post;
foreach ($pageposts as $post):
setup_postdata($post);
if(empty($pin_posts[$post->meta_value])){
$slider_query_count--;
$pin_posts[$post->meta_value] = $post;
array_push($postid_in_pin, $post->ID);
}
endforeach;
endif;
You can add a custom meta field (Tutorial) in post section and than can filter the post while fetching the date from database by the order of sticky posts like this ..
$pageposts = get_posts(array(
'post_type' => 'services',
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => 'post_sticky'
));
Please let me know If you need more assistance. Thanks