I'm building a cinema site,
- In posts I store the Movies
- I have a post_type name "box-office" , this post type have 1-10 custom fields, with i can select the movies stored in post's. locul_1 - is one of that.
How can I display on front page the movie attached to that custom field I want to display on front page 5 movies In post type BoxOffice I have 2 categories (box-office-sua, and another one)
Custom Fields : locul_1,locul_2,locul_3,locul_4,locul_5
In addition, if somoene knows how to do that, I want when I add new post on Post Type Box-Office, I want in front page to automate change with last post from Box-Office, let say category box-office-sua
See image:
What is retrieving the code down? See:
<?php
$posts = get_posts(array(
'post_type' => 'box-office',
'meta_key' => 'locul_1',
));
if( $posts ):
foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<div class="bi">
<?php if(get_field('locul_1') != ""){foreach(get_field('locul_1') as $post_object): ?>
<div class="bi-img">
<?php
if ( ! $img = get_field('img', $post_object->ID ) )
$img = '/wp-content/uploads/noimage1.jpg';
?>
<a href="<?php echo get_permalink($post_object->ID); ?>">
<img src="/scripts/timthumb.php?src=<?php echo urlencode($img); ?>&h=55&w=40&zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>"/></a></div>
<div class="bi-po">1.<span class="bi-b">
<?php $key="incasari_totale"; echo get_post_meta($post_object->ID, $key, true); ?> <b>$</b>
<img class="bi-u" src="/wp-content/themes/movies/images/<?php $key="box_clasament_img"; echo get_post_meta($post->ID, $key, true); ?>" alt="Tip Clasament Box Office" title="Tip Clasament Box Office"/></span></div>
<div class="bi-linie"></div>
<div class="bi-ti"><a href="<?php echo get_permalink($post_object->ID); ?>">
<?php echo get_the_title($post_object->ID) ?></a></div>
<div class="bi-tiro"><?php $key="titluro"; echo get_post_meta($post_object->ID, $key, true); ?></div>
<?php endforeach;}?>
</div>
<?php
endforeach;
wp_reset_postdata();
endif;
?>
Solved..