Home Forums General Issues Article Relationship


Article Relationship

    • homax

    • July 23, 2013 at 7:20 pm

    I would like to use the article relationship to display articles from a category of a other custom post type.

    But I can’t find a code snipped for the Article Relationship. Can someone please post some snipped.

    Thank you.

    • Elliot

    • July 24, 2013 at 12:33 pm

    Hi @homax

    Have you looked over the relationship documentation?

    • homax

    • July 24, 2013 at 4:54 pm


    yes I take a look there. I allready testet it with this code.

    But it doesn’t work.

    <?php if(get_field('news-kategorie')) { ?>

    <?php $posts = get_field('news-kategorie');

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

    <div class="news-kategorie">
    <?php if ( has_post_thumbnail()) { ?>
    <div style="float:left;margin-right:5px;width:75px;high:75px;">
    <?php the_post_thumbnail('thumbnail'); ?>
    <?php } ?>

    <h4 style="margin-top:30px;">"><?php the_title(); ?></h4>

    <?php endforeach; ?>
    <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>

    <?php endif; ?>

    <?php } ?>

    And in the German Version there are different this which I can choose. One is “Beziehung” and the other which I use here is “Artikel-Beziehung”. But for the “Artikel-Beziehung” I haven’t found a several documentation.

    • Elliot

    • July 25, 2013 at 1:04 pm

    Hi @homax

    Thanks for the code.

    Can you elaborate one what is going wrong with the code?

    Have you debugged any of the variables? eg:

    $posts = get_field('myfieldname');
    echo '<pre>';
    	print_r( $posts );
    echo '</pre>';
    • homax

    • July 25, 2013 at 5:09 pm


    ok I wan’t to descripe the problem.

    My Mainsetings for this field are the following. I Think you don’t need more setting information ore did you need some spezial infos?

    Feld-Typ: Artikel-Bezeihung
    Artikel-Beziehung: News Kategorien
    Feld-Typ: Auswahlmenü
    Nichts (NULL) erlauben? Nein
    Lade & Speichere Einträge im Artikel: Not marked
    Rückgabewert: Datei

    When I’m looking in the Frontend I won’t get displayed the Newsarticles of the category “News Kategorien”. There will be linked the hello world post and a attchment. But the hello world post is not in the “News Kategorien”. And I have delete them, it is only in the trash folder.

    When I put the debug code inside I get this response.

    stdClass Object
        [term_id] => 7
        [name] => Category Name
        [slug] => category-name
        [term_group] => 0
        [term_taxonomy_id] => 8
        [taxonomy] => newskategoeie
        [description] => 
        [parent] => 0
        [count] => 1

    There was at [name] an [slug] the right Name inside. But I won’t displays them here.

    • Elliot

    • July 26, 2013 at 3:04 pm

    Hi @homax

    Your previous code assumes that the value of $posts = get_field('news-kategorie'); is an array. However, your result proves otherwise.

    Your result is not an array, it is a single post object.

    This is why your loop does not work.

    • homax

    • July 26, 2013 at 5:37 pm

    Ok Thank you. Which Code I must use to display only the posts of the selected category from the taxonomy newskategoeie?

    Thank you for your help.

    • homax

    • August 20, 2013 at 3:27 am

    have nobody a Idea?

    • Elliot

    • August 20, 2013 at 2:56 pm

    Hi @homax

    Sorry, this question is outside the scope of this support forum.

    There is no issue here with ACF, just a general WP / programing question. Please use another forum such as Stack overflow.

    Thanks for understanding. Unfortunately, I do not have time to solve developer questions which are not specific to ACF.


    • homax

    • August 21, 2013 at 4:46 am


    thanks for your answer. Isn’t it possible to display the posts of a category which I choose in AFC in the WP-Admin. Because I haven’t found a Tutorial here on the page how I can include this in the theme.

    • Elliot

    • August 21, 2013 at 2:40 pm

    Hi @homax

    It is possible, because ACF can save postmeta or the connection from post to term.

    All you need to do is use the native WP_Query class to do any querying you wish.

    There are plenty of docs on this site as to how to query custom field values.

    How to query for taxonomy data? This is not ACF territory, that is why I recommend google.

    Please remember ACF is only a UI interface for the native WP functionality. You are not restricted to the ACF API at all!


Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.