我有两个几乎相同的查询。一个人在某个时间戳之前检查帖子,另一个人在某个时间戳之后检查pts。但是,用于未来帖子的帖子具有所有必要的值,并用于创建指向那些事件的链接,其中之前的帖子由于某种原因而不是:(
以下是代码:
$previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
FROM $wpdb->posts
LEFT OUTER JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT OUTER JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
LEFT OUTER JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id =$wpdb->terms.term_id )
WHERE ( $wpdb->posts.post_date < '$thisyear-$thismonth-01'
AND $wpdb->terms.slug = 'events'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'post')
ORDER BY post_date DESC
LIMIT 1");
$next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
FROM $wpdb->posts
LEFT OUTER JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT OUTER JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
LEFT OUTER JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id =$wpdb->terms.term_id )
WHERE ( $wpdb->posts.post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
AND $wpdb->terms.slug = 'events'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'post')
ORDER BY post_date ASC
LIMIT 1");
以下是使用这些值的代码:
<tr>';
if ( $previous ) {
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
} else {
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>';
}
$calendar_output .= "\n\t\t".'<td class="pad"> </td>';
if ( $next ) {
$calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' »</a></td>';
} else {
$calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>';
}
$calendar_output .= '
</tr>
摘要:
什么错了?!
答案 0 :(得分:0)
很难说出来的是什么,但我的猜测是&#39; date&#39;字段类型严格为date
,而在第二个查询中,您尝试将其用作某种datetime
。它可以是yyyy-mm-dd
但不是yyyy-mm-dd hh:mm:ss
。
另一个猜测是,这不是特定于SQL的,例如$last_day
未设置或字符串格式错误等。
无论如何,请考虑以后的两个建议:
JOIN
和其他东西,错误仍然存在。所以说,只需尝试将其缩减为SELECT * FROM table WHERE ( $wpdb->posts.post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
。