Forum Replies Created

  • Thanks for your reply – of course – having it bundled in ACF would defeat the purpose!

    Not a major issue – if I come across a function solution I will post it here.

  • Nailed it. Thanks.

    A mixture of WordPress Class $wpdb ( and your functions.

    Saved me (for the moment) from having to write a Save to Database function using WordPress. Also means I can keep my Custom Admin Fields all together in ACF, a bit neater that way.

    RoyalSlider places its data in a table called wp_new_royalsliders (obviously table prefix will be custom to each developers WordPress tables).

    add_filter('acf/load_field/name=media_gallery_slider', 'my_acf_royalslider_choices'); 
    function my_acf_royalslider_choices($field){
      $field['choices'] = array();
      // Required to make use of the wpdb Class
      global $wpdb;
      // Query the database
      $query = $wpdb->prepare('SELECT * FROM %1$s ORDER BY ID ASC', 'wp_new_royalsliders');
      $results = $wpdb->get_results($query);
      // Check for $results
      if(!empty($results)) :
      foreach($results as $result) :
          $value = $result->id;
          $label = $result->name;
          $field['choices'][ $value ] = $label; 
      return $field;
  • Well it took me a day of searching, but I hit upon the solution. Hope this helps someone to avoid the same trouble.

    $values = get_field('notes_added');
    foreach ($values as $value){
      echo '<table><tr><td>'.$value['user_meta']['nickname'].'</td><td>'.$value['note_text'].'</td></tr></table>';
  • Point taken. I will go and Google how to do some proper debugging. Currently learning WordPress by myself, with very little guidance – and I am not experienced with PHP at all – any chance you can give me a pointer where I’m going wrong in the meantime?

    Sorry, I don’t mean to waste other people’s time through laziness, I assure you this is not the case. I’ve spent several hours trying to figure this out already.

  • Another brave yet misguided attempt – tried to get closer to your example above – am I getting close?

    if( get_field('notes_added') )
      while( has_sub_field('user_meta') )
        $values = get_sub_field('user_meta');
        $content = get_sub_field('note_text');
      echo '<h1>Notes</h1><table>';
      foreach($values as $value)
        echo '<tr><td>' . $value['nickname'] . '</td> <td>'.$content. '</td></tr>';
      echo '</table>';
  • Hi elliot, I am attempting to do the same thing, but the username field is part of a Repeater. So it is an array within an array!

    Very new to WordPress (though have been kicking goals the last few days!) – can you give me a possible example I can work from?

    Obviously the code below is dodge, but show you what i am trying to do. My repeater is ‘notes_added’, it contains a sub-field ‘user_meta’ which currently spits out an array of all user meta information, like ashley described. It also has a sub-field ‘note_text’ – not an array and requires no filtering. I only want to display the NICKNAME of the user on the page, in a table cell.

    if(get_field('notes_added')): ?>
      <?php while(has_sub_field('notes_added')): ?>
        <tr><td><?php the_sub_field('user_meta', 'nickname'); ?></td> <td><?php the_sub_field('note_text'); ?></td></tr>
      <?php endwhile; ?>
    <?php endif; ?>

    Hope you can help, thanks.

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

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.