MCG
MCG

Reputation: 513

Wordpress Database Query - Get latest Value from a Row depending on two other Columns

If "$Post_id" = "post_parent" and "user_ID" = "post_author" then i need to get "guid" as Variable. But how?

I already have those variables: $post_id (is the same value of "post_parent") $user_id (is the same value of "post_author")

In the Table (i think it called table right?) "posts" i have three Columns "post_parent", "post_author" and "guid".

But i really don´t know who to do that. I already check this, but don´t know how to work with it: http://codex.wordpress.org/Function_Reference/wpdb_Class

Upvotes: 0

Views: 1537

Answers (1)

MCG
MCG

Reputation: 513

Ok, Did it myself. Here´s the working code:

$post_id = $info->get_post_ID();
$comments = $wpdb->get_results("
  SELECT post_author, post_parent, guid
  FROM $wpdb->posts
  WHERE post_author = $info->user_id
  && post_parent = ".$post_id."
  ORDER BY comment_count
  DESC LIMIT 1");

Upvotes: 1

Related Questions