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.

I have been using the advanced custom fields plugin and very much appreciate its abilities.

I have a page on the website i'm working on called About Us and within that page, there is contained, a list of staff members (4 in total). I built this list of staff members using the add on repeater field in the advanced custom field plugin.

I am also developing a single page template devoted to information about the specialist industry area called "treatments", data is output from the main custom post loop of the same name. There are 4 individual custom post types containing this information.

Each member of staff is solely responsible for one of the four treatments. Therefore when a single page view of a specific treatment custom post data is output, I would like to append that information with the relevant staff member in charge of that treatment.

This code below grabs everything from the about us page template in this case using the page id of 89. Not quite what I am after as I need to take a particular row in page id 89 and see if that is a matching pair for the page being fed into the single-treatments.php page

The code is along the right lines however.

<?php
$other_page = 89;
?>
<?php if(get_field('about_the_practioner' , $other_page )): ?>
<?php while(the_repeater_field('about_the_practioner' , $other_page)): ?>
<h4><?php the_sub_field('header' )?><span><?php the_sub_field('title' )?></span></h4>
<?php endwhile; ?>
<?php endif; ?>

Is there a way of grabbing the relevant row data from the staff member repeater field depending on what treatment custom post has been fed into the single page template?

share|improve this question
1  
tl;dr. Can you perhaps be more concise as regards your actual question? You are more likely to get help that way. –  vancoder Mar 22 '13 at 17:29
    
Ok I'll give it a go –  Jonathan Beech Mar 22 '13 at 17:34

2 Answers 2

up vote 0 down vote accepted

Rather than outputting all rows, you can check each row in a loop and only output it if something matches.

In this example, there's a treatment field within the repeater that is the value of the name of the treatment post. If the two match, output the other values:

$other_page = 89;
$practioners = get_field( 'about_the_practioner' , $other_page );
foreach( $practioners as $practioner ):
    if( get_the_title() == $practioner['treatment'] ):
        echo '<h4>' . $practioner['title'] . '</h4>';
    endif;
endforeach;

As an added bonus, you can create a select field to select the treatment post for each practitioner by dynamically adding the post titles as select field values. See the ACF documentation for the acf_load_field filter. Inside the filter function, you can query for all treatment posts and add each title as a select option.

share|improve this answer
    
Thanks so much for your help @Milo. I'm pleased to have solved this one. –  Jonathan Beech Mar 23 '13 at 20:00

After some helpful hints from @Milo, I added this code to my single-treatments page. The about us page had a page link field contained within each piece of staff member repeater data. This page link, linked to the relevant specialist treatment page so was clearly a perfect candidate to use as a match with the current single-treatments page permalink.

I used the output of this field to match the permalink of the current page using the get_permalink function. I can see advantages of @milo's idea too, eg if the staff member became involved in two or more treatment specialisms you could have radio buttons to check those values. the relevant practioner would appear on both single-treatment posts.

                <?php if(get_field('about_the_practioner'  , $other_page )): ?>

                        <?php while(the_repeater_field('about_the_practioner'  , $other_page)): ?>


                <?php if (strcasecmp(get_sub_field('page_link'),get_permalink())==0) {?>
                 <div class="staff lightgrey-background clearfix">

                    <figure class="colleague_excerpts">
                        <?php if(get_sub_field('image')): ?>
                        <img src="<?php the_sub_field('image' ) ?>" alt="<?php the_sub_field('image_alt_text'); ?>">
                        <?php else: ?>
                        <img src="http://placehold.it/160x160&text=Awaiting Image">
                        <?php endif; ?> 
                        <img src="http://placehold.it/200x200&text=Awaiting Image">
                    </figure>
                    <div class="description">
                        <header>
                            <h4><?php the_sub_field('header')?><span><?php the_sub_field('title')?></span></h4>

                        </header>
                        <p><?php the_sub_field('text') ?></p>
                        <a href="<?php the_sub_field('page_link')?>" class="button"><?php the_sub_field('page_link_text') ?></a>

                    </div>

                </div>
                <?php }?>

                <?php endwhile; ?>

                <?php endif; ?>
share|improve this answer

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.