Support » Plugins and Hacks » [Resolved] Sorting and Adding function issue

[Resolved] Sorting and Adding function issue

  • jyiwebadmin



    I tried to add custom code to functions.php for one of my post types, but error occurs resulting in not displaying site.

    I removed the code and still left with sorting issue. I want to sort by organizational hierarchy, but page, for the same post type, is sorted by ‘date’. Other features were tested. None worked for me.

    This is the link.



Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Michael Beckwith


    Hi Lauren,

    Yeah, the “get code” stuff isn’t working out of the box, in 0.8, but is fixed in 0.8.1, but I haven’t been given permission to release it yet. The 0.8 output just needs some correcting with quotes and a couple other things. Can’t be pasted and saved as is.

    Regarding the rest of the post, I’m assuming the team members are all posts in your custom post type. What method are you using to query for them and display? One huge query that you separate out? Many queries that grab each “section”?



    Hi Michael,

    Thank you for your immediate response!! For the last month, I have been having issues with the Custom Post Types UI plugin. My entire website is based on this plugin. It is one of the best plugins I’ve used.


    $the_query = new WP_Query(array( ‘post_type’=>’staff’,
    ‘staff-category’=>$member_category, ‘orderby’=>’date’, // Prefer orderby job_title or something similar
    ‘order’=>’ASC’ ‘posts_per_page’=>’-1′));


    if($the_query->post_count != 0){
    //$str = ‘<h3>’.str_replace(“;”, “,”,$wpdb->get_var(“SELECT name FROM $wpdb->terms WHERE slug = ‘”.$member_category.”‘”)).'</h3><ul class=”our_team”>’;
    $str = ‘<h3>’.str_replace(“;”, “,”,$catname).'</h3><ul class=”our_team”>’;

    while ( $the_query->have_posts() ) : $the_query->the_post();
    $job_title = get_post_meta($the_query->post->ID, ‘job-title’, true);
    $department = get_post_meta($the_query->post->ID, ‘department’, true);
    $university = get_post_meta($the_query->post->ID, ‘university’, true);
    $email = get_post_meta($the_query->post->ID, ’email’, true);

    if(has_post_thumbnail()) {
    $url = wp_get_attachment_url( get_post_thumbnail_id($the_query->ID));
    } else {
    $url = get_bloginfo(“template_url”).’/images/anon_large.png’;
    $str .= ‘

  • <div class=”thumbnail” style=”background-image: url(‘.$url.’)” ></div>’;
    $str .= ‘<div class=”description”>’;
    $str .= ‘<h5>post->ID).'”>’.get_the_title().’</h5>’;
    if($job_title!=”) $str .= ‘‘.$job_title.’
    if($department!=”) $str .= $department.’
    if($university!=”) $str .= $university.’
    if($email!=”) $str .= ‘‘.$email.’‘;
    $str .= ‘</div>’;
    endwhile; // end of the loop.
    $str .= ”;
  • return $str;


    global $wpdb;
    $ccfTable = $wpdb->prefix . “ccf_Value”;
    $t = $wpdb->prefix . “terms”;
    $tt = $wpdb->prefix . “term_taxonomy”;
    $query = “SELECT *
    FROM $ccfTable
    RIGHT JOIN $tt ON ($tt.term_id = $ccfTable.term_id)
    LEFT JOIN $t ON ($tt.term_id = $t.term_id)
    WHERE $tt.taxonomy = ‘staff-category’ AND $tt.count <> ‘0’
    ORDER BY field_value”;

    $staffCats = $wpdb->get_results($query);
    $orderedStaff = ”;
    $unorderedStaff = ”;
    foreach($staffCats as $saffCat){
    if($saffCat->field_value != ”){
    $orderedStaff .= get_members_by_category($saffCat->slug,$saffCat->name);

    $unorderedStaff .= get_members_by_category($saffCat->slug,$saffCat->name);

    }echo $orderedStaff;
    echo $unorderedStaff;


Plugin Author Michael Beckwith


A paste from pastebin.com would have been a better option, but I won’t fault you for that.

From the looks of it, you could use a bit more in your query arguments, check out http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters and the meta_value parameter. It’ll help you to sort by the custom field values on the posts.



Thank you.

I learn something new everyday.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Sorting and Adding function issue’ is closed to new replies.