Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Im building a cinema site,

  • In post's 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 atached 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 somone know how to do that, i want when i add new post on Post Type Box-Office, i want in front page to automate chage with last post from Box-Office, let say categoty box-office-sua

See image : http://i45.tinypic.com/a5o3k.jpg

Wath is retriving the code down See - http://i47.tinypic.com/25hcvvt.jpg

<?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..

share|improve this question
    
    
yes, i read it, but im not so good with php, i learn day by day, in not understand so good the code, so i'm asking for a little help, if i knew i did't post here... –  Batman Jan 25 '13 at 2:40
    
But at least you can try to copy the code there and apply to your problem, then it's not "write the code for me" but "I tried this, why it doesn't work?". The second type receives more answers than the first. –  brasofilo Jan 25 '13 at 3:11
    
hy bransofilo, i update the code but it retrive me the post from last post 1 iulie-7 iulie 2012 (please see the picture).. i now see somewone answerr the question, i give that a try.. remember i do not want the code to be exact, i try for a few hours before i add here a question. Thanks for the answer –  Batman Jan 25 '13 at 3:23
add comment

1 Answer

up vote 0 down vote accepted

Here's the code from the ACF Relationship Field example adapted to your field name. I edited out some of the markup just to simplify things.

A couple of notes:

  1. Use a proper text editor and indent your code so it is readable. A soup of random indentation makes it much more difficult to debug code.

  2. The ACF Relationship Field lets you associate multiple posts in a single field, so having 5 or 10 different fields is unnecessary and just adds extra queries.

.

<?php

$posts = get_field('locul_1');

if( $posts ):
    foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
        <?php setup_postdata($post); ?>

        <div class="bi">
            <div class="bi-img">
                <a href="<?php the_permalink(); ?>">
                    <img src="/scripts/timthumb.php?src=<?php the_field('img'); ?>&h=55&w=40&zc=1" alt="<?php the_title_attribute(); ?>"  title="<?php the_title_attribute(); ?>"/>
                </a>
            </div>
        </div>

    <?php
    endforeach;
    wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
endif;
share|improve this answer
    
thanks, i solved .. it need a little modification to adapt to my theme. I update the post. Thanks Milo. –  Batman Jan 25 '13 at 3:30
    
how can i addapt this to get the content with the number.. Ex: 1,2,3,4,5,6 - first movie,second.. Now to retrive the number <div class="bi-po">1.<span class="bi-b"> of the movie. how can i get it to display acording to the insert of the movie in advance custom fields? –  Batman Apr 15 '13 at 22:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.