custom wp_query with pagination
-
hello,
i fetch the post based on the country,
<?php setup_postdata($post); ?>
<div class=”post-page”><div class=”row”>
<?php
if ( get_query_var(‘paged’) ) { $paged = get_query_var(‘paged’); }
elseif ( get_query_var(‘page’) ) { $paged = get_query_var(‘page’); }
else { $paged = 1; }$args = array(
‘post_type’ => ‘post’,
‘post__not_in’ => array(12329, 12333, 12355, 12382), // THIS IS THE LINE
‘posts_per_page’ => 20,
‘paged’ => $paged,
);query_posts($args);
if($paged ==1){
$pag =$paged;
}else{
$pag=($paged-1)*20;
}$query = “
SELECT *
FROM $wpdb->posts
WHERE $wpdb->posts.post_country = ‘”.$usercounty.”‘
AND $wpdb->posts.post_type = ‘post’
ORDER BY $wpdb->posts.ID DESC LIMIT “.$pag.”,20″;$pageposts =$wpdb->get_results($query);
if ($pageposts):
global $post;
foreach ($pageposts as $post):
setup_postdata($post);
?>
<div class=”col-lg-3 col-sm-5 col-xs-12″>
<div class=”all-posts”>
” class=”view-img” target=”_blank”>
<?php
if (has_post_thumbnail()) {
the_post_thumbnail();
} else {
global $post, $wp_embed;
$youtube_video_url = get_post_meta($post->ID, ‘cf_video’, true); //store youtube URL in variableif (!empty($youtube_video_url)) { //Check Youtube URL is entered or not
if(the_post_thumbnail()){
the_post_thumbnail();
} else {
$url = explode(“?”,$youtube_video_url);
$exp = explode(“=”,$url[1]);
if($exp[1]){
?><img src=”https://img.youtube.com/vi/<?php echo $exp[1];?>/default.jpg” alt=”” style=”width:250px;height:250px” />
<?php } else {?>
<img src=”<?php bloginfo(‘template_url’); ?>/images/gplay.png” alt=”” />
<?php }?>
<?php }?>
<?php // echo $wp_embed->run_shortcode(‘[embed]‘ . $youtube_video_url . ‘[/embed]‘);
} else {
$content = get_the_content();?>
<?phpif(catch_that_image( $content )){
echo catch_that_image( $content );
} elseif (strpos($content,’poster’) !== false) {?>
<img src=”<?php echo just_text_in_quotes($content);?>” style=”width:250px;height:250px” />
<?php } else {
$trimmed_content = wp_trim_words( $content, 50 );
echo “<div class=’contdetails’><div class=’inndetails’>”.$trimmed_content.”</div></div>”;}
}
}
?></div>
</div>
<?php endforeach; endif;
?>
</div><div class=”view-more”><?php numeric_posts_nav(); ?>
each and every page have 20 post but the pagination count will get all the post in data base. so extra pagination are not showing the post. the pagination have to count the post. please help me..
- The topic ‘custom wp_query with pagination’ is closed to new replies.