Say "Hello!"

  • This field is for validation purposes and should be left unchanged.

Advanced Custom Fields – Using field group ID and relationships to query multiple fields


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<ul>
 <?php
    $model = $post->post_name;
    query_posts(array('category_name' => $model));
    $features = $page->ID;
   
    foreach(get_field('relation', $features) as $relationship): ?>
        <li><strong>Model:</strong> <?php echo get_the_title($relationship->ID); ?></li>
        <?php $groupId = 232; //ID of field group. Get this from the Edit Field Group page url
            if (class_exists('Acf')) {
                $specs = new Acf();
                if (method_exists( $specs, 'get_acf_fields') ) {
                foreach ($specs -> get_acf_fields($groupId) as $field) {
                    $value = get_field($field['name'], $relationship->ID); ?>
                    <?php if ($value) { ?>
                        <li><strong><?php echo $field['label'] ?>:</strong> <?php echo $value ?></li>
                    <?php } ?>  
    <?php } } } ?>                                          
    <?php endforeach; ?>
    <?php wp_reset_query(); ?>
</ul>

Back to Snippets Follow me on GitHub

Ashley Cameron logo
Blog