Home Forums General Issues Article Relationship


Article Relationship

  • 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.

  • Hi,

    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.

  • 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>';
  • Hi,

    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.

  • 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.

  • 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.

  • have nobody a Idea?

  • 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.


  • Hi,

    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.

  • 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!


  • For these individuals, romantic relationships comprise one of the most meaningful aspects of life, and are a source of deep fulfillment.I would like to use the article relationship to display articles from a category of a other custom post type.

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

The topic ‘Article Relationship’ is closed to new replies.