Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- Display yellow stars based on rating -->
- <strong>Rating: </strong>
- <?php
- $nb_stars = intval( get_post_meta( get_the_ID(), 'movie_rating', true ) );
- for ( $star_counter = 1; $star_counter <= 5; $star_counter++ ) {
- if ( $star_counter <= $nb_stars ) {
- echo '<img src="' . plugins_url( 'Movie-Reviews/images/icon.png' ) . '" />';
- } else {
- echo '<img src="' . plugins_url( 'Movie-Reviews/images/grey.png' ). '" />';
- }
- }
- ?>
- DISPLAYING METADATA LINK
- Metadata can be retrieved easily using the get_post_meta() function. In our example above, we saved a post meta field named product_price. We can retrieve the value of this field for a given post using the following code:
- <?php
- // If we are in a loop we can get the post ID easily
- $price = get_post_meta( get_the_ID(), 'product_price', true );
- // To get the price of a random product we will need to know the ID
- $price = get_post_meta( $product_id, 'product_price', true );
- ?>
- <?php
- $args = array(
- 'post_type' => 'product',
- 'tax_query' => array(
- array(
- 'taxonomy' => 'product_category',
- 'field' => 'slug',
- 'terms' => 'boardgames'
- )
- )
- );
- $products = new WP_Query( $args );
- if( $products->have_posts() ) {
- while( $products->have_posts() ) {
- $products->the_post();
- ?>
- <h1><?php the_title() ?></h1>
- <div class='content'>
- <?php the_content() ?>
- </div>
- <?php
- }
- }
- else {
- echo 'Oh ohm no products!';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement