Skip to main content
added 335 characters in body
Source Link
Bysander
  • 1.2k
  • 1
  • 10
  • 28

If you are already on the page of the house (in the loop of the post) you want then something like this should work. I imagine the values are saved as post meta???

If so I had to do something similar and managed to achieve it like this although I'm sure someone out there may have a better way round.

$ThisPostID = get_the_ID();  //simply gets the current post ID
$TheHouseLocation = get_post_meta( $ThisPostID, 'property_location' ); //property_location is probably the meta key name this can be checked with a simple post meta inspector plugin. If so this gets the current 'location' of the house being viewed

 $args=array(
        'post_type' => 'Properties',
        'post_status' => 'publish',
        'meta_key' => 'property_location',
        'meta_value' => $TheHouseLocation,
        'posts_per_page' => -1,
        'ignore_sticky_posts'=> 1,
        );

 $ShowSomeHouses = new WP_Query($args);
 if ($ShowSomeHouses->have_posts()) {
//This bit happens if there are houses in same location look for the else below if there are none.
while ($ShowSomeHouses->have_posts()) : $ShowSomeHouses->the_post();

You could cycle through the post details using calls such as the_title(); or the_content(); here.

OR ADD

$NearbyHouseIDs = get_the_ID(); //This should find the post id's of the houses in same location.
foreach ($NearbyHouseIDs as $nearbyhouse) {

This middle bit gives you the chance to format the display or layout as you wish but by the sounds of it there is already some layout in the template you are using. As I have no idea what the original code is I won't try and recreate it here. the $nearbyhouse is the post ID number of each of those houses found in the area. You can then call custom details like meta & other information using something like get_post_meta( $nearbyhouse, $key, $single );

}
endwhile;
} else echo '<p>There are no nearby houses to show at the moment</p>';
wp_reset_query();  // Turns everything back to normal

DISCLAIMER: This is just a bit of code written on a blog - I have not tested it nor do I claim to be a skilled or gifted coder.

If you are already on the page of the house (in the loop of the post) you want then something like this should work. I imagine the values are saved as post meta???

If so I had to do something similar and managed to achieve it like this although I'm sure someone out there may have a better way round.

$ThisPostID = get_the_ID();  //simply gets the current post ID
$TheHouseLocation = get_post_meta( $ThisPostID, 'property_location' ); //property_location is probably the meta key name this can be checked with a simple post meta inspector plugin. If so this gets the current 'location' of the house being viewed

 $args=array(
        'post_type' => 'Properties',
        'post_status' => 'publish',
        'meta_key' => 'property_location',
        'meta_value' => $TheHouseLocation,
        'posts_per_page' => -1,
        'ignore_sticky_posts'=> 1,
        );

 $ShowSomeHouses = new WP_Query($args);
 if ($ShowSomeHouses->have_posts()) {
//This bit happens if there are houses in same location look for the else below if there are none.
while ($ShowSomeHouses->have_posts()) : $ShowSomeHouses->the_post();
$NearbyHouseIDs = get_the_ID(); //This should find the post id's of the houses in same location.
foreach ($NearbyHouseIDs as $nearbyhouse) {

This middle bit gives you the chance to format the display or layout as you wish but by the sounds of it there is already some layout in the template you are using. As I have no idea what the original code is I won't try and recreate it here.

}
endwhile;
} else echo '<p>There are no nearby houses to show at the moment</p>';
wp_reset_query();  // Turns everything back to normal

DISCLAIMER: This is just a bit of code written on a blog - I have not tested it nor do I claim to be a skilled or gifted coder.

If you are already on the page of the house (in the loop of the post) you want then something like this should work. I imagine the values are saved as post meta???

If so I had to do something similar and managed to achieve it like this although I'm sure someone out there may have a better way round.

$ThisPostID = get_the_ID();  //simply gets the current post ID
$TheHouseLocation = get_post_meta( $ThisPostID, 'property_location' ); //property_location is probably the meta key name this can be checked with a simple post meta inspector plugin. If so this gets the current 'location' of the house being viewed

 $args=array(
        'post_type' => 'Properties',
        'post_status' => 'publish',
        'meta_key' => 'property_location',
        'meta_value' => $TheHouseLocation,
        'posts_per_page' => -1,
        'ignore_sticky_posts'=> 1,
        );

 $ShowSomeHouses = new WP_Query($args);
 if ($ShowSomeHouses->have_posts()) {
//This bit happens if there are houses in same location look for the else below if there are none.
while ($ShowSomeHouses->have_posts()) : $ShowSomeHouses->the_post();

You could cycle through the post details using calls such as the_title(); or the_content(); here.

OR ADD

$NearbyHouseIDs = get_the_ID(); //This should find the post id's of the houses in same location.
foreach ($NearbyHouseIDs as $nearbyhouse) {

This middle bit gives you the chance to format the display or layout as you wish but by the sounds of it there is already some layout in the template you are using. As I have no idea what the original code is I won't try and recreate it here. the $nearbyhouse is the post ID number of each of those houses found in the area. You can then call custom details like meta & other information using something like get_post_meta( $nearbyhouse, $key, $single );

}
endwhile;
} else echo '<p>There are no nearby houses to show at the moment</p>';
wp_reset_query();  // Turns everything back to normal

DISCLAIMER: This is just a bit of code written on a blog - I have not tested it nor do I claim to be a skilled or gifted coder.

added 69 characters in body
Source Link
Bysander
  • 1.2k
  • 1
  • 10
  • 28

If you are already on the page of the house (in the loop of the post) you want then something like this should work. I imagine the values are saved as post meta???

If so I had to do something similar and managed to achieve it like this although I'm sure someone out there may have a better way round.

$ThisPostID = get_the_ID();  //simply gets the current post ID
$TheHouseLocation = get_post_meta( $ThisPostID, 'property_location' ); //property_location is probably the meta key name this can be checked with a simple post meta inspector plugin. If so this gets the current 'location' of the house being viewed

 $args=array(
        'post_type' => 'Properties',
        'post_status' => 'publish',
        'meta_key' => 'property_location',
        'meta_value' => $TheHouseLocation,
        'posts_per_page' => -1,
        'ignore_sticky_posts'=> 1,
        );

 $ShowSomeHouses = new WP_Query($args);
 if ($ShowSomeHouses->have_posts()) {
//This bit happens if there are houses in same location look for the else below if there are none.
while ($ShowSomeHouses->have_posts()) : $ShowSomeHouses->the_post();
$NearbyHouseIDs = get_the_ID(); //This should find the post id's of the houses in same location.
foreach ($NearbyHouseIDs as $nearbyhouse) {

This middle bit gives you the chance to format the display or layout as you wish but by the sounds of it there is already some layout in the template you are using. As I have no idea what the original code is I won't try and recreate it here.

}
endwhile;
} else echo '<p>There are no nearby houses to show at the moment';moment</p>';
wp_reset_query();  // Turns everything back to normal

DISCLAIMER: This is just a bit of code written on a blog - I have not tested it nor do I claim to be a skilled or gifted coder.

If you are already on the page of the house (in the loop of the post) you want then something like this should work. I imagine the values are saved as post meta???

If so I had to do something similar and managed to achieve it like this although I'm sure someone out there may have a better way round.

$ThisPostID = get_the_ID();  //simply gets the current post ID
$TheHouseLocation = get_post_meta( $ThisPostID, 'property_location' ); //property_location is probably the meta key name this can be checked with a simple post meta inspector plugin.

 $args=array(
        'post_type' => 'Properties',
        'post_status' => 'publish',
        'meta_key' => 'property_location',
        'meta_value' => $TheHouseLocation,
        'posts_per_page' => -1,
        'ignore_sticky_posts'=> 1,
        );

 $ShowSomeHouses = new WP_Query($args);
 if ($ShowSomeHouses->have_posts()) {
//This bit happens if there are houses in same location look for the else below if there are none.
while ($ShowSomeHouses->have_posts()) : $ShowSomeHouses->the_post();
$NearbyHouseIDs = get_the_ID(); //This should find the post id's of the houses in same location.
foreach ($NearbyHouseIDs as $nearbyhouse) {

This middle bit gives you the chance to format the display or layout as you wish but by the sounds of it there is already some layout in the template you are using. As I have no idea what the original code is I won't try and recreate it here.

}
endwhile;
} else echo '<p>There are no nearby houses to show at the moment';
wp_reset_query();  // Turns everything back to normal

DISCLAIMER: This is just a bit of code written on a blog - I have not tested it nor do I claim to be a skilled or gifted coder.

If you are already on the page of the house (in the loop of the post) you want then something like this should work. I imagine the values are saved as post meta???

If so I had to do something similar and managed to achieve it like this although I'm sure someone out there may have a better way round.

$ThisPostID = get_the_ID();  //simply gets the current post ID
$TheHouseLocation = get_post_meta( $ThisPostID, 'property_location' ); //property_location is probably the meta key name this can be checked with a simple post meta inspector plugin. If so this gets the current 'location' of the house being viewed

 $args=array(
        'post_type' => 'Properties',
        'post_status' => 'publish',
        'meta_key' => 'property_location',
        'meta_value' => $TheHouseLocation,
        'posts_per_page' => -1,
        'ignore_sticky_posts'=> 1,
        );

 $ShowSomeHouses = new WP_Query($args);
 if ($ShowSomeHouses->have_posts()) {
//This bit happens if there are houses in same location look for the else below if there are none.
while ($ShowSomeHouses->have_posts()) : $ShowSomeHouses->the_post();
$NearbyHouseIDs = get_the_ID(); //This should find the post id's of the houses in same location.
foreach ($NearbyHouseIDs as $nearbyhouse) {

This middle bit gives you the chance to format the display or layout as you wish but by the sounds of it there is already some layout in the template you are using. As I have no idea what the original code is I won't try and recreate it here.

}
endwhile;
} else echo '<p>There are no nearby houses to show at the moment</p>';
wp_reset_query();  // Turns everything back to normal

DISCLAIMER: This is just a bit of code written on a blog - I have not tested it nor do I claim to be a skilled or gifted coder.

Source Link
Bysander
  • 1.2k
  • 1
  • 10
  • 28

If you are already on the page of the house (in the loop of the post) you want then something like this should work. I imagine the values are saved as post meta???

If so I had to do something similar and managed to achieve it like this although I'm sure someone out there may have a better way round.

$ThisPostID = get_the_ID();  //simply gets the current post ID
$TheHouseLocation = get_post_meta( $ThisPostID, 'property_location' ); //property_location is probably the meta key name this can be checked with a simple post meta inspector plugin.

 $args=array(
        'post_type' => 'Properties',
        'post_status' => 'publish',
        'meta_key' => 'property_location',
        'meta_value' => $TheHouseLocation,
        'posts_per_page' => -1,
        'ignore_sticky_posts'=> 1,
        );

 $ShowSomeHouses = new WP_Query($args);
 if ($ShowSomeHouses->have_posts()) {
//This bit happens if there are houses in same location look for the else below if there are none.
while ($ShowSomeHouses->have_posts()) : $ShowSomeHouses->the_post();
$NearbyHouseIDs = get_the_ID(); //This should find the post id's of the houses in same location.
foreach ($NearbyHouseIDs as $nearbyhouse) {

This middle bit gives you the chance to format the display or layout as you wish but by the sounds of it there is already some layout in the template you are using. As I have no idea what the original code is I won't try and recreate it here.

}
endwhile;
} else echo '<p>There are no nearby houses to show at the moment';
wp_reset_query();  // Turns everything back to normal

DISCLAIMER: This is just a bit of code written on a blog - I have not tested it nor do I claim to be a skilled or gifted coder.