Forums

[resolved] Add custom query into ...query? (5 posts)

  1. doodlebee
    Member
    Posted 1 year ago #

    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.

  2. doodlebee
    Member
    Posted 1 year ago #

    Oh yay! I found it!

    I don't know that it'll work (yet) but it's a point in the right direction, and that's all I needed :)

    The post that led me to (what I think is) the answer:
    http://wordpress.org/support/topic/148005?replies=18#post-846120

    And the "injection stuff" I was looking for:
    http://codex.wordpress.org/Function_Reference/get_terms

    yee-haw - now off to play!

  3. MichaelH
    moderator
    Posted 1 year ago #

    Hey d!

    If I understand correctly, then Otto's suggestion in this topic may help:
    http://wordpress.org/support/topic/157515

  4. doodlebee
    Member
    Posted 1 year ago #

    Thanks Michael! I'll look at that one too :)

  5. doodlebee
    Member
    Posted 1 year ago #

    Woo-hoo! Okay, thanks to that post, I also found this post, which helped *immensely*. (ahh...Kaf. is there *nothing* you cannot do?)

    I've got it working like a charm now. Thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.