Support

Account

Home Forums Front-end Issues getting specific value from user type field

Solved

getting specific value from user type field

  • I hope this question wont be below standards of this forum.

    Im trying to list posts with two values :
    – topic of post (custom text field)
    – name and last name from user type custom field (promoter) that is associated with specific role Ive created

    When Im using the_field(‘promoter’), Im getting data in shape like:
    4, Promotor, Promotorski, promotor, promotor, Promotor Promotorski, [email protected], , 2016-07-20 06:45:23, , – which are all meta of that field. I want to print specific one which would be Promotor Promotorski in this case.

    Also I realized any get_ functions doesnt get data. the_field is working but echo get_field is not. If I would be able to get at least ID of that associated user it would be wonderful.

    Its a code Ive got right now. Hope that Polish name of fields wont hurt you much.

    
    <?php
    /**
     * Template Name: browse_posts
     */
    ?>
    
    <?php get_header(); ?>
    
    <?php
    $current_user = wp_get_current_user();
    $args=array(
      'post_type' => 'tematy_prac',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1,
      'meta_query' => array(
      array(
      'key' => 'status_pracy',
      'value' => 'Zaakceptowany',
      )
      )
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
    
        <p>
          <a href="<?php the_permalink() ?>"><?php the_field('temat'); ?></a>
          <?php
           the_field('promotor');
            ?>
        </p>
        <?php
      endwhile;
    }else{
      echo "brak tematów";
    }
    wp_reset_query(); 
    ?>
    <?php get_footer(); ?>    
    

    I really apologize if this question is too dumb.

  • Okay. Im stupid. I just…:

    ?php
    $array = get_field('promotor');
    print_r($array['display_name']);
       

    and it works.
    Its all because user field is array, so it cant be used with echo.
    I think you should delete this post. Im sorri!

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

The topic ‘getting specific value from user type field’ is closed to new replies.