• Hi Guys,

    I am using wordpress to create a website for a company, they need to have a section for showing off the staff members, those staff members need to be shown in a specific order, so I have added an extra meta value to the user profile called ‘profile_order’… I have checked phpmyadmin and the data has saved correctly to the user_meta table.

    What I am trying to do is call the id of all the users and then sort those via my extra ‘profile_order’ field that I have added… see below for my code… I have tried and tried and tried, but cant see anything that will let me do this ??

    <?php
    										$wp_user_search = new WP_User_Query(array( 'fields' => 'ID', 'order' => 'profile_order'));
    										$editors = $wp_user_search->get_results();
    										print_r($editors);
    
    										foreach ($editors as $editor) { ?>
    
    											<div class="staff-member">
                                                	<h1><a href="<?php bloginfo(url); ?>/author/<?php the_author_meta( 'user_login', $editor ); ?>"><?php the_author_meta( 'first_name', $editor ); ?></a></h1>
                                                    <p><?php the_author_meta( 'user_description', $editor ); ?></p>
                                                    <?php echo get_avatar( $editor); ?>
                                                    <?php the_author_posts_link(); ?>
                                                </div>
    										<?php }
    									?>
Viewing 7 replies - 1 through 7 (of 7 total)
  • Try ‘orderby’ instead of ‘order’

    HTH

    David

    Hey David,

    Sorry to post in this but I can not figure out how to message you. I saw your response to someone in another post.

    I am finished with a site I am making for a friend and ready to launch but cannot figure out how to add two social media icons just above the nav menu on the top right.

    viapiana.wheresdaniel.com

    Any thoughts our help would be greatly appreciated!

    Thanks,

    Daniel

    Hi Daniel,
    It is better to start a new topic, seen as bad form to hi-jack another users topic.

    Did you look at the Navigation Social Icons post, it looks like it cannot find the images?

    If you need more help post a new topic.

    Regards

    David

    Thread Starter simonbrown

    (@simonbrown)

    Thanks for the suggestion David, I had already tried that… unfortunately it doesn’t pick it up…

    There must be someway of calling the meta field to order it ?? racking my brains here…

    Had a quick Google, have a look at this post about sorting by a meta_key, and this one is specific for users

    HTH

    David

    Thread Starter simonbrown

    (@simonbrown)

    Thanks david that second one was perfect!!! thankyou, only thing ill mention is that i needed them the oposite order so in the code I switched

    return ($a->profile_order > $b->profile_order) ? -1 : 1;
    to
    `return ($a->profile_order > $b->profile_order) ? 1 : -1;’

    and it worked like a charm

    THANK YOU!

    Great thing Google sometimes you can hit a solution in the first few links!

    Could you mark this topic as resolved please.

    David

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Displaying Authors and then Ordering by meta_value’ is closed to new replies.