qebas
qebas

Reputation: 89

Filtering the post_author outside the wordpress loop

I have a Mysql query set outside the wordpress loop, like the one below, which doesn't work. I would like to know how can I filter the sql results based on the author that created the post.

global $post;
$post_author = $post->post_author;
$sQuery = "SELECT DATE_FORMAT((post_date), '%M/%Y') 'Month',
       FROM wp_posts p WHERE p.post_author = '$post_author'

Any assistance is appreciate it.

Thank you,

Upvotes: 0

Views: 319

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269953

You have an extra comma after 'Month'. Try this:

$post_author = $post->post_author;
$sQuery = "SELECT DATE_FORMAT((post_date), '%M/%Y') 'Month' FROM wp_9691posts p WHERE p.post_author = '$post_author'";

I also added the final " to enclose the query string.

Upvotes: 1

Related Questions