• Hi guys, it’s my very first troubleshooting WP post on this forum. I’m a true php greenhorn and I just start my big adventure with WP developping – it’s so passionating.

    Well, there is a thing that I’m stuck with.
    I’m using OceanWP child-theme.
    I created 2 CPT that are linked via ACF relationship fields :
    cpt “patristiques” that has each its own cpt “auteur”.

    I’ve created a single-patristiques.php and archives-patristiques.php
    I want to replace standard meta data and to display acf field “auteur”.

    My code :

    <?php
    /**
     * The Patristiques template for displaying post meta.
     *
     * @package OceanWP WordPress theme
     */
    // Exit if accessed directly
    if ( ! defined( 'ABSPATH' ) ) {
    	exit;
    }
    ?>
    
    <?php 
    
    $posts = get_field('auteur');
    
    if( $posts ): ?>
        <ul>
        <?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
            <h4 class="meta-auteur">par : <a href="<?php the_permalink($p->ID); ?>"><?php echo get_the_title( $p->ID ); ?></a></h4>
        <?php endforeach; ?>
        </ul>
    <?php endif; ?>

    It works preety fine for the first one but loop seems don’t work.
    I tried to replace the content of original OceanWP meta.php file with my acf content – no success. I believe this would be a piece of cake for you.

    Great thanks for any help,

    • This topic was modified 5 years, 10 months ago by agatstone.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display a loop with ACF fields in archive-cpt’ is closed to new replies.