Jump to content

Conditional php query on Wordpress


princesohrab
 Share

Recommended Posts

Hey all, I am creating a site for a realtor/estate agent and I am trying to search specific listings and display the relevant posts on a page as thumbnails item. Using the code below, how do I add a condition to display for example, only properties which has taxonomies (1 Bedroom only). The code below is checking for everypost and display them, but I want it to be specific to taxonomies. The taxonomies I have for the listings are as follows:FlatsHouseApartmentStudio, etc........ All I want is a condition to dis play specific properties. I have the following lines which finds the posts and then display them.

<div class="post-container short">   <?php if(have_posts()):?>   <?php while(have_posts()):the_post();?>   <div class="post-title">    <h1><a href="<?php the_permalink();?>"><?php the_title();?> </a></h1>       </div><!--post-title-->      <?php if($post->post_content != ''): ?>    <div class="post-content">	 <?php the_content();?>    </div><!--post-contetn-->    <?php endif; ?>   <?php endwhile;?>     <?php endif;?>   </div><!--post-container-->

Thanks in advance.

Link to comment
Share on other sites

Sorry guys I think this is the code that displays the thumbnails-------------------- <!-- lettings - Listings starts--> <div class="row"> <h3 id="latest-listings"><span>Properties To Let</span></h3> <?php $the_query = new WP_Query('showposts=6&post_type=listings') ?> <?php if($the_query->found_posts == 0){ for($i=1; $i<=6; $i++){echo dummy_listings();} }else{ ?> <?php while ( $the_query->have_posts() ) : $the_query->the_post();?> <div class="four columns listing"> <div class="post-container short"> <?php echo has_post_thumbnail() ? my_get_image(true) : my_get_image_blank(true);?> <h5><a href="<?php the_permalink();?>"><?php the_title();?> </a></h5> <p>added <?php the_time('F j, Y');?><a class="small button" href="<?php the_permalink();?>">→</a></p> </div> </div> <?php endwhile; wp_reset_postdata();?> <?php } ?> </div><!--end row--><!-- short term lets - Listings ends-->

Link to comment
Share on other sites

I've gone through it and I still can't figure it out. How do I add the specific query here?<?php $the_query = new WP_Query('showposts=6&post_type=listings') ?> Or si it here?<?php while ( $the_query->have_posts() ) : $the_query->the_post();?> All I need this query to do is list all the posted properties that have the taxonomy "Flats" only and leave the rest. I'm very novice to php.Thanks for your help

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...