0

I'm creating relationships on post types using this funciton:

private function setObjectTerms($last_insert_id){

      //INSERT course_type/RELATIONSHIP
      wp_set_object_terms($last_insert_id,$this->course_type,'course-type'); 

  }

Above, the course type can be 'free', or 'paid', and the $last_insert_id is just a number..

Anyway I keep getting this error, and have no idea why:

WordPress database 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 'AS tr INNER JOIN AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.ob' at line 1]

SELECT tr.term_taxonomy_id FROM AS tr INNER JOIN AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tr.object_id IN (15534) AND tt.taxonomy IN ('course-type')

The strange thing is I been using this same function, and it has worked. I just don't get why the SQL produced is incorrect. Can anyone point me in the right direction?

2 Answers 2

1

The wp_term_taxonomy and wp_term_relationships table names are missing from this failed query, so, unsurprisingly, MySQL gags on it.

Internally in WordPress, the global $wpdb object furnishes those table names to the function that's building the query. If it has empty strings for the table names, it hasn't (yet) been initialized.

You may not have set up WordPress correctly before calling this function.

See this: How can I initialize wpdb class in a php file?

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the answer..I get where you're coming from, I've checked how my wpdb class is initialized, and it is just like the solution of that question. Really stumped, because the exact same function works when implemented from a different class...I can't see any differences with the working class and this one...i guess I'll sleep on it
0

I found a solution!

$wpdb->set_prefix('wp_');

See here fellow battlers

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.