• Resolved oltrecomics

    (@oltrecomics)


    Hello everyone,
    I have this code in function.php:
    https://gist.github.com/anonymous/3d8e3f3d878ca10dfdd2
    I would like to add a new field that should be displayed after the content.
    After the last line of code I have added this function:

    add_action('__after_content','my_acf',100);
    function my_acf() {
    if ( ! is_single() )
        return;
    <?php
    
    $posts = get_field('fumetti');
    
    if( $posts ): ?>
    	<div class="box-tipo"><div class="box-campo">Relazione Fumetti:</div><div class="box-risultato"><ul class="box-voci">
    	<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
    
    	    	<li><a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?></a></li>
    
    	<?php endforeach; ?></ul></div></div>
    
    <?php endif; ?>
    }

    Unfortunately it seems not to work. Where did I go wrong?

Viewing 4 replies - 1 through 4 (of 4 total)
  • <?php endif; ?>
    }

    should be :

    <?php endif;
    }

    Thread Starter oltrecomics

    (@oltrecomics)

    Unfortunately it does not work yet.
    This is all the code that I put in functions.php:
    https://gist.github.com/anonymous/02c8687d64da14a57e24

    Something missing?

    Can you explain “doesn’t work”?
    Do you get errors or it just doesn’t display anything after the content?

    I think you get an error:

    add_action('__after_content','my_acf',100);
    function my_acf() {
    if ( ! is_single() )
        return;
    <?php

    remove that <?php

    Thread Starter oltrecomics

    (@oltrecomics)

    Thanks d4z_c0nf,
    the problem was just that one.

    I thought I had figured out how to work the php language… obviously I did not understand anything. 🙂

    You’re always the number one.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Add custom Field after content’ is closed to new replies.