Reputation: 197
I would like to access the date value from this object in WordPress, but I can't get any results.
$dates = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) FROM wp_posts
ORDER BY post_date");
foreach($dates as $date){
echo $date->YEAR(post_date);
}
stdClass Object
(
[YEAR(post_date)] => 2010
)
stdClass Object
(
[YEAR(post_date)] => 2011
)
stdClass Object
(
[YEAR(post_date)] => 2012
)
stdClass Object
(
[YEAR(post_date)] => 2013
)
How can I fix this?
Upvotes: 0
Views: 56
Reputation: 6311
try this
print_r($date->{'YEAR(post_date)'});
or simply change the name in the query
Upvotes: 1
Reputation: 432
You can change the name of "YEAR(post_date)", try:
SELECT DISTINCT YEAR(post_date) as pDate FROM wp_posts ORDER BY post_date
You can call with: $date->pDate;
Note: I added as pDate
to the query
Upvotes: 1