Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

[Resolved] MySQL Syntax Error!

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch

lpxxfaintxx

Established Member
Impact
13
MySQL Syntax Error!

[You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND wp_posts.ID = wp_term_relationships.object_id AND wp_term_relationships.' at line 7]

SELECT DISTINCT ID, post_title, post_date, wp_terms.term_id as post_category FROM wp_posts, wp_terms, wp_term_relationships, wp_term_taxonomy WHERE wp_terms.term_id = AND wp_posts.ID = wp_term_relationships.object_id AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.term_id = wp_terms.term_id AND ID != 500 AND post_status = 'publish' ORDER BY post_date DESC LIMIT 400


This is the full query:


$category_check = " WHERE {$tp}terms.term_id = " . $c->cat_ID . " ";

$last_posts = (array)$wpdb->get_results("
SELECT DISTINCT ID,
post_title,
post_date,
{$tp}terms.term_id as post_category
FROM {$tp}posts, {$tp}terms, {$tp}term_relationships, {$tp}term_taxonomy
{$category_check}
AND {$tp}posts.ID = {$tp}term_relationships.object_id
AND {$tp}term_relationships.term_taxonomy_id = {$tp}term_taxonomy.term_taxonomy_id
AND {$tp}term_taxonomy.term_id = {$tp}terms.term_id
{$ddop_inc_current}
AND post_status = 'publish'
ORDER BY post_date {$newest_check}
LIMIT {$ddop_num}



Any idea what's wrong?
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
wp_terms.term_id = AND

equals AND? :o

$c->cat_ID is returning nada
 
0
Close
Yes -NC- has pinpointed your problem. $c->cat_ID is not producing anything so wp_terms.term_id is not being compared to anything.
 
0
Close
Ah! Any Wordpress/MySQL guru's want to help me get this figured out? :)
 
0
Close
What WP version are you using?
 
0
Close
rough hack off the top of my head:

if( is_numeric( $c->cat_ID ) ) {
$category_check = " WHERE {$tp}terms.term_id = " . $c->cat_ID . " ";
}else{
$category_check = " WHERE 1=1 ";
}
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back