WordPress.org

Ready to get started?Download WordPress

Forums

Custom Post Type UI
[resolved] Sorting and Adding function issue (5 posts)

  1. jyiwebadmin
    Member
    Posted 9 months ago #

    Hello,

    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.

    Lauren

    http://wordpress.org/plugins/custom-post-type-ui/

  2. Michael Beckwith
    Member
    Plugin Author

    Posted 9 months ago #

    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"?

  3. jyiwebadmin
    Member
    Posted 9 months ago #

    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.

    Query:

    $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'));

    Loop:

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

  4. <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.
    wp_reset_query();
    $str .= '';

    return $str;
    }

    Display:

    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);

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

    }
    }echo $orderedStaff;
    echo $unorderedStaff;

    Lauren

  • Michael Beckwith
    Member
    Plugin Author

    Posted 9 months ago #

    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.

  • jyiwebadmin
    Member
    Posted 9 months ago #

    Thank you.

    I learn something new everyday.

  • Reply

    You must log in to post.

    About this Plugin

    About this Topic

    Tags