This is an ongoing request, trying to do maximize some code to display a list of Accomodation by Country, of a certain Type, and a specific Region.
So for example, a list of ALL accommodations in FRANCE, By Hotel Rating (1,2,3,4,5), and then by Region (Paris, Marseille etc…)
Listing will be
-Hotel 1Star
–Marseille
—Hotel 1
—Hotel 2
–Paris
—Hotel 1
—Hotel 2
-Hotel 2Star
etc.. etc…
Each Hotel entry is a custom post called Accomodation
I have 3 taxonomies, countries (ie France), accomodation-type (ie Hotel 1 star), region (ie Paris).
The listing of accommodations “lives” on a country page, so the value of the country is already know. (ie $termcountry->name)
My code is a below:
$taxonomy2 = 'accomodation-type';
$termsacc = get_terms("accomodation-type",array('orderby' => 'slug', 'order' => 'ASC'));
foreach ($termsacc as $termaccomodation) {
$taxonomyregion = 'region';
$termsreg = get_terms("region",array('orderby' => 'slug', 'order' => 'ASC'));
foreach ($termsreg as $termregion) {
$query = array(
'post_type' => 'accomodation',
'accomodation-type' =>$termaccomodation->name,
'country' =>$termcountry->name,
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => 48,
'tax_query' => array(
array(
'taxonomy' => $taxonomyregion,
'field' => 'slug',
'terms' => $termregion->name,
'orderby' => 'title',
'order' => 'ASC',
)
)
);
query_posts($query);
$count = 1; //First we set the count to be zeo
if(have_posts() ) {
$termaccomodation->slug = str_replace("%e2%80%98", "", $termaccomodation->slug);
$termaccomodation->slug = str_replace("%e2%80%99", "", $termaccomodation->slug);
if($termregion->name=="General"){
$regionname = "";
}else{
$regionname = " - ".$termregion->name;
}
$id = '';
$new_id = ++ $id;
?>
<a name="<?php echo $new_id."-".$termaccomodation->slug."-".$termregion->slug;?>"></a>
<div id="accitem">
<?php echo "<h3>".$termaccomodation->name."".$regionname."</h3>";?>
<?
while (have_posts()) : the_post();
$linkacc = get_custom_field("AccomodationLink");
?>
I do my loop stuff and display the accom list.
then close my loop
<?php endwhile; wp_reset_query();?>
This is working, but REALLY SLOW… and I am pretty sure it’s not the optimal/best way of doing it.
Could I pick your brains on this?
Help!
cheers
s