• I have a site with a template that lists property by two types for lease, and for sale. I am creating a loop to grab these by taxonomy for_lease, and for_sale. I’m wondering if I can create an if statement that grabs the category for_sale if page_is for sale page, and grab the category for_lease if the page_is for lease. I’m super new to the wordpress loop and if else statements, so bear with me. Here’s my loop so far which works great for grabbing just one taxonomy and category…I just want to make it a little smarter.

    <?php
    $args = array(‘post_type’ => ‘property’, ‘proptype’ => ‘for_lease’);
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); ?>

    <div>all my stuff that goes in the loop </div>

    <?php endwhile; ?> ?

    Any help would be much appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The question is: How will you identify which page is which?

    One way would be to use the Page title:

    <?php
    if ($post->post_title == 'For Lease') {
       $args = array('post_type' => 'property', 'proptype' => 'for_lease');
    } else {
       $args = array('post_type' => 'property', 'proptype' => 'for_sale');
    }
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); ?>
    Thread Starter drhodes

    (@dthornborrow)

    That worked perfectly! Thank you very much.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘loop to grab category only on certain page’ is closed to new replies.