• Resolved Doodlebee

    (@doodlebee)


    OMG – that’s just a bizarre question, I know. I wasn’t sure how to put it.

    I was wanting to know if there was a way to “add in” a custom “orderby” into a query_posts function. I’ve been trying to figure this out for weeks now, and I’m just at a loss.

    yes, I know I can follow this tutorial, which I have tried to do it this way as well, but I’ve been unsuccessful thus far – and basically if I do that, I’m just reinventing the wheel.

    What I need to do is order my posts – on my tag archive – by a meta value I’ve placed in the usermeta table. (I can get it to work with the codex page lined above, but I can’t get my tag archive to display correctly – I run into the same issue. I can order by the meta, but now my tag order won’t work – so one way or another, something isn’t going right).

    If I could *just* somehow pull in that meta value into the orderby, it would solve all my problems.

    Right now, I’m at this point:

    global $wpdb;
    $custom = "SELECT * FROM $wpdb->usermeta as um
               LEFT JOIN $wpdb->users as u ON um.user_id = u.id
               LEFT JOIN $wpdb->posts as p ON um.user_id = p.post_author
               AND um.meta_key = 'article_position'
               ORDER BY um.meta_value ASC";
    
    //now the query that puts it all together
         query_posts('tag='.$tagname.'&showposts=-1&author=-1'.$custom);

    But of course it’s not working. I kind of didn’t expect it to, but right now I’m to the point where I’m just trying *anything*. I’ve even messed with the core query.php file – against my better judgement (it didn’t go anywhere, so I changed it back.)

    I keep thinking I’ve seen something like the above before – where you can “inject” a custom something-or-other in the query and it’ll still work, but for the life of me I can’t recall where. query_vars seems like it might be a possibility, but I don’t see an example of it, and the definition doesn’t make it too clear to me as to what it does. (Actually, a LOT of stuff on this page looks like, if I knew how to work with it, it might help – but alas I’m not sure what you do with it.)

    Anyway, if someone can point me in the right direction, I’d sure appreciate it.

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Add custom query into …query?’ is closed to new replies.