WordPress.org

Ready to get started?Download WordPress

Forums

Displaying Authors and then Ordering by meta_value (8 posts)

  1. simonbrown
    Member
    Posted 2 years ago #

    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 }
    									?>
  2. Digital Raindrops
    Member
    Posted 2 years ago #

    Try 'orderby' instead of 'order'

    HTH

    David

  3. wheresdaniel
    Member
    Posted 2 years ago #

    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

  4. Digital Raindrops
    Member
    Posted 2 years ago #

    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

  5. simonbrown
    Member
    Posted 2 years ago #

    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...

  6. Digital Raindrops
    Member
    Posted 2 years ago #

    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

  7. simonbrown
    Member
    Posted 2 years ago #

    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!

  8. Digital Raindrops
    Member
    Posted 2 years ago #

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

    Could you mark this topic as resolved please.

    David

Topic Closed

This topic has been closed to new replies.

About this Topic