Last active
March 13, 2019 12:34
-
-
Save manoj-singh-developer/d19726fc377fc6e5048ab29a75e3983f to your computer and use it in GitHub Desktop.
Revisions
-
manoj-singh-developer revised this gist
Mar 13, 2019 . 1 changed file with 37 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -119,4 +119,40 @@ if($query->have_posts()){ } 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(); ?> -
manoj-singh-developer revised this gist
Mar 13, 2019 . 1 changed file with 27 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -93,3 +93,30 @@ 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>'; ?> -
manoj-singh-developer revised this gist
Mar 13, 2019 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -90,4 +90,6 @@ Country: United Kingdom Subject: Biology Subject: Chemistry Subject: Neurology ========================================================================= https://css-tricks.com/snippets/wordpress/using-custom-fields/ ========================================================================== -
manoj-singh-developer revised this gist
Mar 13, 2019 . 1 changed file with 11 additions and 17 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -79,21 +79,15 @@ 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 -
manoj-singh-developer revised this gist
Mar 13, 2019 . 1 changed file with 31 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -46,7 +46,38 @@ 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; ?> -
manoj-singh-developer revised this gist
Mar 11, 2019 . 1 changed file with 11 additions and 54 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,31 +2,6 @@ <?php $args = array( 'post_type' => 'hotel_listing', //remember this is-case sensitive @@ -52,16 +27,19 @@ 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); } ?> @@ -85,27 +63,6 @@ foreach($my_query->posts as $post) { -
manoj-singh-developer revised this gist
Mar 11, 2019 . 1 changed file with 65 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -23,6 +23,71 @@ wp_reset_query(); ?> <?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); ?> <h1> <?php echo $post->post_title; ?> </h1> <?php echo $am = get_post_meta($post->ID, 'price', true); echo $am = get_post_meta($post->ID, 'details', true); } ?> -
manoj-singh-developer created this gist
Mar 11, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ <?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() ) : $releaseQuery->the_post(); $c_id = get_the_ID(); echo get_the_title(); echo get_post_meta($c_id, 'price', true); endwhile; endif; wp_reset_query(); ?>