How to Display ACF Relationship Custom Field as Link to Specific Custom Post?

OK. I am reading this ACF tutorials, but I am not getting into this.

I have 2 post types: Lists and Contacts.

Read More

Every List must be related to some Contact, and I use Relationship custom field type (list_supplier), which is limited to only one choice (or Contact).

All I have to do is to display link on Lists template as Title of Contact post which is now related with that List.

Plugin
http://wordpress.org/plugins/advanced-custom-fields/

UPDATE:

OK. I am close to solve this, but I have some problems with filter.

Here is the code I am using in my template:

 <?php $contacts = get_field('list_supplier'); ?>
                    <?php if( $contacts ): ?>
                        <?php foreach( $contacts as $contact ): ?>
                            <a href="<?php echo get_permalink( $contact->ID ); ?>" target="blank"><?php echo get_the_title( $contact->ID ); ?></a>
                        <?php endforeach; ?>
                    <?php endif; ?>

In one moment I make it work on front end, but there was some problem with filters.
When I add some of these filters into functions.php, choices from custom field list_supplier disappear. When I remove filter list_supplier chioces are there, but they are not showing on front end.

I know that problem is in filter, but I dont know how to wrote it.

Related posts

1 comment

  1. Finaly, I make this working.

    I put this in my template:

    <?php $contacts = get_field('list_supplier'); ?>
    <?php if( $contacts ): ?>
        <?php foreach( $contacts as $contact ): ?>
            <a href="<?php echo get_permalink( $contact->ID ); ?>" target="blank"><?php echo get_the_title( $contact->ID ); ?></a>
        <?php endforeach; ?>
    <?php endif; ?>
    

    And here is the filter I am using

    <?php
    function my_acf_load_field( $field )
    {
        $field['choices'] = array(
            'custom' => 'My Custom Choice'
        );
        return $field;
    }
    
    // acf/load_field/key={$field_key} - filter for a specific field based on it's name
    add_filter('acf/load_field/key=field_525c37d91ae8d', 'my_acf_load_field');
    ?>
    

Comments are closed.