Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can I add a custom field to an array? To complicate matters, custom field is on the Author's page, not on a regular post. It's added via Advanced Custom Fields. Typically, that field value would be called with <?php the_field(author_status); ?>.

Here's the full code I'm working with right now.

 <?php
 //displays all users with their avatar and their posts (titles)
 $blogusers = get_users_of_blog();
 if ($blogusers) {
   foreach ($blogusers as $bloguser) {
     echo '<div class="content-slider-body">';
    $user = get_userdata($bloguser->user_id);
     echo '<div class="grid col-140">' . get_avatar( $user->ID, 128 ) . '</div>';
     $args=array(
       'author' => $user->ID,
       'post_type' => 'post',
       'post_status' => 'publish',
       'posts_per_page' => 1,
       'caller_get_posts'=> 1
     );
     $my_query = null;
     $my_query = new WP_Query($args);
     if( $my_query->have_posts() ) {
       //echo 'List of Posts for ' . user->user_firstname . ' ' . $user->user_lastname;
       while ($my_query->have_posts()) : $my_query->the_post(); ?>
         <div class="grid col-460 fit"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
            <!--post-meta-->
            <div class="post-data"><span class="date"><?php the_time('F jS, Y') ?></span> by <?php the_author_posts_link(); ?>
                <?php if ( comments_open() ) : ?>
                    <span class="comments-link">
                <?php comments_popup_link(__('Leave a Comment &darr;', 'responsive'), __('1 Comment &darr;', 'responsive'), __('% Comments &darr;', 'responsive')); ?>
                    </span>
                <?php endif; ?>
            </div>
    <br /><?php the_excerpt(); ?></div>

    <?php echo '<span class="rsTmb">' . $user->user_firstname . ' ' . $user->user_lastname . '</span></div>'; ?>
        <?php
       endwhile;
     }
   wp_reset_query();  // Restore global post data stomped by the_post().
   }
 }
 ?>

OMG, I got it to work! Placed this where I need it in the repeatable area:

<?php the_author_meta( 'author_status', $user->ID ); ?>

share|improve this question
    
If you've found the answer, post it, dont edit your question –  Tom J Nowell Oct 3 '12 at 18:16
    
I did post the answer at the end of the thread as well. –  Phantasmix Oct 3 '12 at 18:22

3 Answers 3

$args = array(
    'meta_query' => array(
        array(
            'key' => 'author_status',
            'value' => 'active',
                    'compare' => 'NOT LIKE'
        )
    )
 );

This Url works

http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

share|improve this answer
    
Thanks for trying, Deepa Dhole. That code breaks the page. –  Phantasmix Oct 3 '12 at 13:51
$author_status = get_post_meta(get_the_ID(), 'author_status');

This will return an array of all the values for that term. If you just want a single string of the first value, you can add a true as a third argument.

http://codex.wordpress.org/Function_Reference/get_post_meta

### EDIT

In light of the additional information from your comment, you need to be accessing the information directly from the WP_User object itself.

Try this:

$author_status = $user->get('author_status');

That should do it for you.

https://codex.wordpress.org/Class_Reference/WP_User#get.28_.24key_.29

share|improve this answer
    
HeathenJesus, sorry, don't understand where this should go. Just to clarify, I'm showing a carousel on the homepage, where author's name is the Tab title. Slide content is the author's latest post. Author_status would go next to the latest post. –  Phantasmix Oct 3 '12 at 15:00
    
Perhaps I am misunderstanding — what content has the custom field in question? Is there an "Author" custom post type? Or is "Author Status" associated with the post? –  heathenJesus Oct 3 '12 at 15:10
    
"Author_status" is associated with the author, it is set on the User Profile page along with their bio and email. I'm open to other suggestions, this is not set in stone. But all of this is for use on the Homepage only. Thanks! –  Phantasmix Oct 3 '12 at 15:18
    
Check out my edit — it should do what you need it to. –  heathenJesus Oct 3 '12 at 15:27
    
The edit isn't working, sorry. I think author_status must be added to functions.php somehow (beware, you're dealing with a dummy here). Looking at this right now: tommcfarlin.com/get-user-by-meta-data –  Phantasmix Oct 3 '12 at 15:50
up vote -1 down vote accepted

This was added to the area with repeatable content: <?php the_author_meta( 'author_status', $user->ID ); ?>

Replace author_status with the name of your AUTHOR CUSTOM FIELD.

Solution is from here: http://codex.wordpress.org/Function_Reference/the_author_meta

share|improve this answer
    
Please add an explanation to turn that fragment into an answer. –  toscho Oct 3 '12 at 16:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.