Support

Account

Home Forums Front-end Issues Using ACF values for custom shortcode

Unread

Using ACF values for custom shortcode

  • Hello, I’m trying to create a custom shortcode which shows the users linked to the page.

    I use the following function to create the shortcode:

    // Display Employees
    function user_list_shortcode() {
    $users = get_field("medewerkers");
    if( $users ):
    ob_start();
    ?>
    <ul class="user-list">
    <?php foreach( $users as $user ): ?>

  • <?php echo $user->user_avatar; ?>
    user_url; ?>"><?php echo $user->display_name; ?>
  • <?php endforeach; ?>

    <?php
    return ob_get_clean();
    endif;
    }
    add_shortcode('user_list', 'user_list_shortcode');

    For a page where I use this I have assigned 2 users.
    When I var_dump($user) I get both of the users array set with these correct values but when I use them like above them I only get empty list items.

    $user->user_avatar should return an image according to the array and both other fields are existing and filled.
    Any help would be appreciated

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.