Felder, die Verbindungen zwischen Inhalten herstellen. Erfordert PRO-Lizenz.
Beziehung
Multi-Select-Beitragsauswahl, die ein Array von Beiträgen zurückgibt.
php
$related = get_field( 'related_articles' );
// return_format = 'object': Returns array of WP_Post objects
// return_format = 'id': Returns array of post IDs, e.g., [10, 25, 33]
if ( $related ) :
echo '<div class="related-articles">';
echo '<h3>Related Articles</h3>';
foreach ( $related as $post ) : setup_postdata( $post ); ?>
<article class="related-card">
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail( 'medium' ); ?>
<?php endif; ?>
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<?php the_excerpt(); ?>
</article>
<?php endforeach;
wp_reset_postdata();
echo '</div>';
endif;
// When return_format = 'id', use get_posts for more control
$related_ids = get_field( 'related_articles' );
if ( $related_ids ) {
$posts = get_posts( [
'post__in' => $related_ids,
'orderby' => 'post__in',
'posts_per_page' => -1,
] );
foreach ( $posts as $p ) {
echo '<a href="' . get_permalink( $p ) . '">' . esc_html( $p->post_title ) . '</a>';
}
}Beitragsobjekt
Wählen Sie einen oder mehrere Beiträge aus.
php
$featured = get_field( 'featured_post' );
// return_format = 'object': Returns WP_Post object (or array if multiple)
if ( $featured ) {
echo '<a href="' . get_permalink( $featured ) . '">';
echo esc_html( $featured->post_title );
echo '</a>';
}
// Multiple post objects
$highlights = get_field( 'highlighted_posts' );
if ( $highlights ) {
foreach ( $highlights as $post ) {
echo '<div class="highlight">';
echo '<h4>' . esc_html( $post->post_title ) . '</h4>';
echo '</div>';
}
}Seitenlink
Gibt die Permalink-URL eines ausgewählten Beitrags/einer ausgewählten Seite zurück.
php
$link = get_field( 'destination_page' );
// Returns: URL string (permalink of selected page)
echo '<a href="' . esc_url( $link ) . '" class="btn">Go to page</a>';Taxonomie
Wählen Sie Taxonomiebegriffe aus.
php
$term = get_field( 'primary_category' );
// return_format = 'object': Returns WP_Term object
if ( is_object( $term ) ) {
echo '<a href="' . esc_url( get_term_link( $term ) ) . '">' . esc_html( $term->name ) . '</a>';
}
// Multiple terms
$tags = get_field( 'related_tags' );
if ( $tags ) {
echo '<div class="tags">';
foreach ( $tags as $tag ) {
echo '<a href="' . esc_url( get_term_link( $tag ) ) . '" class="tag">' . esc_html( $tag->name ) . '</a>';
}
echo '</div>';
}Benutzer
Wählen Sie einen oder mehrere WordPress-Benutzer aus.
php
$author = get_field( 'guest_author' );
// return_format = 'array': Returns ['ID' => 5, 'display_name' => 'John', 'user_email' => '...']
if ( $author ) {
echo '<div class="author-card">';
echo get_avatar( $author['ID'], 64 );
echo '<span>' . esc_html( $author['display_name'] ) . '</span>';
echo '</div>';
}—