Skip to content

Instantly share code, notes, and snippets.

@amitkolloldey
Created January 11, 2017 04:53
Show Gist options
  • Save amitkolloldey/bc8381b73a58a2c2cc6137f3b59a2ffe to your computer and use it in GitHub Desktop.
Save amitkolloldey/bc8381b73a58a2c2cc6137f3b59a2ffe to your computer and use it in GitHub Desktop.
Custom Post Query in Wordpress
<?php
/*
* Template Name: Homepage
*/
get_header();?>
<?php
global $post;
$args = array( 'posts_per_page' => 24, 'post_type'=> 'villa', 'orderby' => 'menu_order', 'order' => 'ASC' );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post);
$post_id = get_the_ID();
$price = get_post_meta($post_id, '_bh_price', true);
$bedrooms = get_post_meta($post_id, '_bh_bedrooms', true);
$permax = get_post_meta($post_id, '_bh_permax', true);
$other_information = get_post_meta($post_id, '_bh_other_information', true);
$total_reviews = get_post_meta($post_id, '_bh_total_reviews', true);
?>
<div class="villa-item col-sm-4">
<div class="img-villa"><?php the_post_thumbnail();?>
</div>
<div class="rate">
<span> From </span>
<div class="price">
$ <?php echo $price;?>
<span>/night</span>
</div>
</div>
<div class="about-villa">
<div class="villa-name">
<h2><?php the_title();?></h2>
</div>
<div class="short-description"><?php the_excerpt();?>
</div>
<div class="features row">
<div class="features-1 col-sm-6">
<span> <i class="fa fa-bed" aria-hidden="true"></i> <?php echo $bedrooms;?> Bedrooms</span>
<span> <i class="fa fa-users" aria-hidden="true"></i> <?php echo $permax;?> Peoples </span>
</div>
<div class="features-2 col-sm-6">
<span> <i class="fa fa-check-circle" aria-hidden="true"></i> <?php echo $other_information;?> </span>
<span> <i class="fa fa-star" aria-hidden="true"></i> <?php echo $total_reviews;?> Reviews </span>
</div>
</div>
</div>
<a class="btn btn-default" href="<?php the_permalink();?>" role="button">VIEW DETAIL</a>
</div>
<?php endforeach;?>
<?php get_footer();?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment