<?php get_header(); ?>
<script src="https://m2mediadev.com/qw/wp-content/themes/queens-wharf-2020/assets/dist/scripts/main.min.js"></script>

<?php
$grouping = '';

if (!$grouping) {
	$grouping = "explore-groups";
}

// TODO: Explore page alternate to 'expreince' page with query value

// Make explore links manually set instead of relying on luck (page with same names)
?>

<section class="page-section main-content-section">
	<div class="container">
				<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

						<div class="singular-header">
							<div class="single-header-post-type">
								Explore Queen's Wharf Brisbane
							</div>
							<a href="/explore/" class="control control-back inverse icon-arrow-thin-left">
		                        <span>Back</span>
		                    </a>
						</div>

						<h1 class="center-align"><?php the_title(); ?></h1>

						<div class="single-post-feature-image nospace-mobile">
							<?php the_post_thumbnail();?>
						</div>
		<div class="row">

			<div class="col s12 m10 push-m1 l8 push-l2">

						<div class="index-content <?php if ( '' !== get_post()->post_content ) { echo ' plain_text'; } ?>">

							<div class="explore-content-header">

								<div class="explore-meta">	
									<?php 
									//list all taxonomy terms related to this object
									global $post; 
									//get taxonomies available from post
									$taxonomy_objects = get_object_taxonomies( get_post_type(), 'objects' );
										$taxonomies = array();
										foreach($taxonomy_objects as $taxonomy_object) {
									  	array_push($taxonomies, $taxonomy_object); 
									} 
									?>

									<?php foreach ($taxonomies as $taxonomy): ?>
										<?php
										//list all taxonomies 
										$terms = wp_get_post_terms( $post->ID, $taxonomy->name ); 
										?>			
										<?php if ($terms): ?>
											<ul class="term-buttons-list">
												<?php foreach($terms as $term): ?>

													<?php 
												//	if (get_the_permalink(get_page_by_title($term->name))): //comment due to get_page_by_title is deprecated since version 6.2.0! error
												    if ($term->name): ?>
													<li >
											<a href="https://queenswharfbrisbane.com.au/explore/" class="btn btn-gray">
															<?php echo $term->name; ?>
														</a>
													</li>
												<?php endif; ?>
												<?php endforeach; ?>
											</ul>
										<?php endif; ?>
									<?php endforeach; ?>
								</div>


                 				<a href class="btn btn-outline-gray btn-gray-outline addthis_button_expanded">Share</a>
								
							</div>

							<?php the_content(); ?>
						</div>


			</div>
		</div> 


		<?php endwhile; else : ?>
			<p><?php _e( 'Sorry, nothing was found.' ); ?></p>
		<?php endif; ?>
	</div>
</section>


<?php	get_template_part('partials/template', 'pagesections');  ?>



<!-- begin custom related loop, isa -->
 
<?php 
global $post;
$post_type = get_post_type();
// arguments

/*global $post; 
//get taxonomies available from post
$taxonomy_objects = get_object_taxonomies( get_post_type(), 'objects' );
	$taxonomies = array();
	foreach($taxonomy_objects as $taxonomy_object) {
  	array_push($taxonomies, $taxonomy_object); 
} */
global $post; 

// Get the post type and ensure it's a valid string
$post_type = get_post_type();
if (!$post_type) {
  // Handle the case where post type is not valid
  error_log('Invalid post type.');
  return;
}

// Get taxonomies available from post type and ensure it's an array
$taxonomy_objects = get_object_taxonomies($post_type, 'objects');
if (!is_array($taxonomy_objects)) {
  // Handle the case where taxonomies are not returned as an array
  error_log('Taxonomies not returned as an array.');
  return;
}

$taxonomies = array();
foreach($taxonomy_objects as $taxonomy_object) {
  array_push($taxonomies, $taxonomy_object); 
}

// Now you can safely use $taxonomies


// $custom_terms = array();
foreach ($taxonomies as $taxonomy): 
	$custom_terms = wp_get_post_terms( $post->ID, $taxonomy->name ); 
endforeach;

// print_r($custom_terms);
if ($custom_terms[0]) {
	$slug = $custom_terms[0]->slug;

	$args = array(
	'post_type' => get_post_type(),
	'posts_per_page' => -1,
	'post__not_in' => array ($post->ID),
	'tax_query' => array(array(
	            'taxonomy' => 'explore-groups',
	            'field' => 'slug',
	            'terms' => $slug
	        ))
	);
	$related_items = new WP_Query( $args );
	// loop over query
	if ($related_items->have_posts()) : ?>


		<section class="page-section related-posts style-med clearfix">
			<div class="section-inner card_grid">
			<div class="container">
				<h2 class="center-align section-title">Explore more <?php echo $custom_terms[0]->name; ?></h2>
					
					<div class="explore-slider" data-slick='{
					"dots": false,
					"infinite": true,
					"arrows": false,
					"slidesToShow": 4,
					"slidesToScroll": 4,
					"adaptiveHeight": true,
					"respondTo": "window",
					"swipeToSlide": true,
					"responsive": [
					{
					"breakpoint": 1280,
					"settings": {
					"slidesToShow": 4,
					"slidesToScroll": 4,
					"infinite": false,
					"dots": false
					}
					},
					{
					"breakpoint": 940,
					"settings": {
					"slidesToShow": 2,
					"slidesToScroll": 2
					}
					},
					{
					"breakpoint": 480,
					"settings": {
					"slidesToShow": 1,
					"slidesToScroll": 1
					}
					}
					]
					}'>
						<?php while ( $related_items->have_posts() ) : $related_items->the_post();
						?>	
							<div class="card-slide">
								<?php 
								global $post;
								$thumbURL = get_the_post_thumbnail_url($post->ID, 'card-size');
			    				displaySimpleCard($thumbURL, '' , get_the_title(), '', get_the_permalink($post->ID)); 
								?>
							</div>

						<?php
						endwhile;
					?>
				</div>
				<div class="explore-slider-footer center-align">
					<div class="paginator-center text-color text-center explore-slider-nav">
							<ul>
									<li class="control control-back inverse icon-arrow-thin-left slick-prev">
			                        <span>Back</span>
									</li>
									<li class="slick-next control control-back inverse icon-arrow-thin-right">
			                        <span>Next</span>	
									</li>
							</ul>
					</div>
					<a href="https://queenswharfbrisbane.com.au/explore" class="btn btn-dark explore-back-button">
						Keep exploring the masterplan
					</a>
				</div>
			</div>
			</div>
		</section>

	<?php endif;
}
// Reset Post Data
wp_reset_postdata();
?>
	 


<?php get_footer(); ?>