Last active
March 13, 2019 12:34
-
-
Save manoj-singh-developer/d19726fc377fc6e5048ab29a75e3983f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php /* Template Name: Hotel Custom */ ?> | |
| <?php | |
| $args = array( | |
| 'post_type' => 'hotel_listing', //remember this is-case sensitive | |
| 'posts_per_page' => -1, | |
| ); | |
| $releaseQuery = new WP_Query( $args ); | |
| if ( $releaseQuery->have_posts() ) : | |
| while ( $releaseQuery->have_posts() ) : | |
| $mn = $releaseQuery->the_post(); | |
| //print_r() | |
| $c_id = get_the_ID(); | |
| //echo get_the_title(); | |
| //echo the_content(); | |
| $am = get_post_meta($c_id, 'price', true); | |
| //print_r($am); | |
| endwhile; | |
| endif; | |
| wp_reset_query(); | |
| $my_query = new WP_Query('post_type=hotel_listing'); | |
| foreach($my_query->posts as $post) { | |
| //print_r($post); | |
| ?> | |
| <?php //echo $post->post_title; ?> | |
| <?php | |
| //echo $am = get_post_meta($post->ID, 'price', true); | |
| //echo $am = get_post_meta($post->ID, 'details', true); | |
| $postId = $post->ID; | |
| $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID )); | |
| $im = $dynamic_featured_image->get_featured_images([$postId]); | |
| //print_r($image); | |
| print_r($im); | |
| } | |
| ?> | |
| ================================================== | |
| <?php | |
| $args = array( | |
| 'post_type' => 'hotel_listing', | |
| 'posts_per_page' => 4 | |
| ); | |
| $query = new WP_Query($args); | |
| while ($query->have_posts()): | |
| $query->the_post(); | |
| print_r($query); | |
| ?> | |
| <h2> <?php the_title(); ?> </h2> | |
| <p>Meta: <?php //echo the_meta()->detail; ?> </p> | |
| <p>Excerpt: <?php echo the_excerpt();?> </p> | |
| <?php | |
| $terms = wp_get_post_terms($query->post->ID, array( | |
| 'hotel_type', | |
| )); | |
| ?> <?php | |
| foreach ($terms as $term): | |
| ?> <p><?php | |
| echo $term->taxonomy; | |
| ?>: <?php | |
| echo $term->name; | |
| ?></p> <?php | |
| endforeach; | |
| ?> <?php | |
| endwhile; | |
| ?> | |
| ===================================================================== | |
| <?php $terms = wp_get_post_terms( $query->post->ID, array( 'country', 'subject' ) ); ?> | |
| <?php foreach ( $terms as $term ) : ?> | |
| <p><?php echo $term->taxonomy; ?>: <?php echo $term->name; ?></p> | |
| <?php endforeach; ?> | |
| Your output would be something like: | |
| Country: United Kingdom | |
| Subject: Biology | |
| Subject: Chemistry | |
| Subject: Neurology | |
| ========================================================================= | |
| https://css-tricks.com/snippets/wordpress/using-custom-fields/ | |
| ========================================================================== | |
| <?php | |
| $term_id = get_queried_object()->term_id; | |
| $args = array( | |
| 'post_type' => 'hotel_listing', | |
| 'tax_query' => array( | |
| array( | |
| 'taxonomy' => 'hotel_type', | |
| 'field' => 'term_id', | |
| 'terms' => array('18'), //put more term ids if required | |
| ), | |
| ), | |
| ); | |
| $query = new WP_Query( $args ); | |
| echo '<ul>'; | |
| if($query->have_posts()){ | |
| while($query->have_posts()){ | |
| $query->the_post(); | |
| echo '<li>' . get_the_title( $query->post->ID ) . '</li>'; | |
| } | |
| // Restore original Post Data once finished, IMPORTANT | |
| wp_reset_postdata(); | |
| } | |
| echo '</ul>'; | |
| ?> | |
| ==================================================================== | |
| <?php | |
| // get the custom post type's taxonomy terms | |
| $custom_taxterms = wp_get_object_terms( $post->ID, 'your_taxonomy', array('fields' => 'ids') ); | |
| // arguments | |
| $args = array( | |
| 'post_type' => 'your_custom_post_type', | |
| 'post_status' => 'publish', | |
| 'posts_per_page' => 3, // you may edit this number | |
| 'orderby' => 'rand', | |
| 'tax_query' => array( | |
| array( | |
| 'taxonomy' => 'your_taxonomy', | |
| 'field' => 'id', | |
| 'terms' => $custom_taxterms | |
| ) | |
| ), | |
| 'post__not_in' => array ($post->ID), | |
| ); | |
| $related_items = new WP_Query( $args ); | |
| // loop over query | |
| if ($related_items->have_posts()) : | |
| echo '<ul>'; | |
| while ( $related_items->have_posts() ) : $related_items->the_post(); | |
| ?> | |
| <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> | |
| <?php | |
| endwhile; | |
| echo '</ul>'; | |
| endif; | |
| // Reset Post Data | |
| wp_reset_postdata(); | |
| ?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment