WITHOUT conditionals, my query runs fine (see attached). As soon as I add the conditional: "post.taxonomy.category" = "Some Category" (or Like or %Like%) I get a column not found error. This is the error:
No results found. Please check if this query is correct! Table Constructor needs a query that returns data to build a wpDataTable.
Error: Unknown column 'post_taxonomy_category' in 'on clause
Here is the SQL:
SELECT post_taxonomy_category_tbl.name AS post_taxonomy_category,
post_meta_date_published_tbl.meta_value AS post_meta_date_published,
post_meta_author_tbl.meta_value AS post_meta_author,
posts_post.post_title AS post_post_title,
posts_post.post_content AS post_post_content
FROM wp2k_posts AS posts_post
INNER JOIN (SELECT name, object_id as id FROM wp2k_terms AS post_taxonomy_category_tbl_terms INNER JOIN wp2k_term_taxonomy AS post_taxonomy_category_tbl_termtaxonomy ON post_taxonomy_category_tbl_termtaxonomy.term_id = post_taxonomy_category_tbl_terms.term_id AND post_taxonomy_category_tbl_termtaxonomy.taxonomy = 'category' INNER JOIN wp2k_term_relationships AS rel_post_taxonomy_category_tbl ON post_taxonomy_category_tbl_termtaxonomy.term_taxonomy_id = rel_post_taxonomy_category_tbl.term_taxonomy_id) AS post_taxonomy_category_tbl
ON post_taxonomy_category_tbl.ID = posts_post.id AND post_taxonomy_category = 'Published & Accepted Papers'
INNER JOIN (SELECT post_meta_date_published_tbl_posts.ID as id, meta_value, meta_key FROM wp2k_postmeta AS post_meta_date_published_tbl_postmeta INNER JOIN wp2k_posts AS post_meta_date_published_tbl_posts ON post_meta_date_published_tbl_postmeta.post_id = post_meta_date_published_tbl_posts.ID AND post_meta_date_published_tbl_posts.post_type = 'post') AS post_meta_date_published_tbl
ON post_meta_date_published_tbl.meta_key = 'date_published' AND post_meta_date_published_tbl.id = posts_post.ID INNER JOIN (SELECT post_meta_author_tbl_posts.ID as id, meta_value, meta_key FROM wp2k_postmeta AS post_meta_author_tbl_postmeta INNER JOIN wp2k_posts AS post_meta_author_tbl_posts ON post_meta_author_tbl_postmeta.post_id = post_meta_author_tbl_posts.ID AND post_meta_author_tbl_posts.post_type = 'post') AS post_meta_author_tbl
ON post_meta_author_tbl.meta_key = 'author' AND post_meta_author_tbl.id = posts_post.ID WHERE 1=1 AND posts_post.post_type = 'post'
WITHOUT conditionals, my query runs fine (see attached). As soon as I add the conditional: "post.taxonomy.category" = "Some Category" (or Like or %Like%) I get a column not found error. This is the error:
No results found. Please check if this query is correct! Table Constructor needs a query that returns data to build a wpDataTable. Error: Unknown column 'post_taxonomy_category' in 'on clause
Here is the SQL:
SELECT post_taxonomy_category_tbl.name AS post_taxonomy_category, post_meta_date_published_tbl.meta_value AS post_meta_date_published, post_meta_author_tbl.meta_value AS post_meta_author, posts_post.post_title AS post_post_title, posts_post.post_content AS post_post_content FROM wp2k_posts AS posts_post INNER JOIN (SELECT name, object_id as id FROM wp2k_terms AS post_taxonomy_category_tbl_terms INNER JOIN wp2k_term_taxonomy AS post_taxonomy_category_tbl_termtaxonomy ON post_taxonomy_category_tbl_termtaxonomy.term_id = post_taxonomy_category_tbl_terms.term_id AND post_taxonomy_category_tbl_termtaxonomy.taxonomy = 'category' INNER JOIN wp2k_term_relationships AS rel_post_taxonomy_category_tbl ON post_taxonomy_category_tbl_termtaxonomy.term_taxonomy_id = rel_post_taxonomy_category_tbl.term_taxonomy_id) AS post_taxonomy_category_tbl ON post_taxonomy_category_tbl.ID = posts_post.id AND post_taxonomy_category = 'Published & Accepted Papers' INNER JOIN (SELECT post_meta_date_published_tbl_posts.ID as id, meta_value, meta_key FROM wp2k_postmeta AS post_meta_date_published_tbl_postmeta INNER JOIN wp2k_posts AS post_meta_date_published_tbl_posts ON post_meta_date_published_tbl_postmeta.post_id = post_meta_date_published_tbl_posts.ID AND post_meta_date_published_tbl_posts.post_type = 'post') AS post_meta_date_published_tbl ON post_meta_date_published_tbl.meta_key = 'date_published' AND post_meta_date_published_tbl.id = posts_post.ID INNER JOIN (SELECT post_meta_author_tbl_posts.ID as id, meta_value, meta_key FROM wp2k_postmeta AS post_meta_author_tbl_postmeta INNER JOIN wp2k_posts AS post_meta_author_tbl_posts ON post_meta_author_tbl_postmeta.post_id = post_meta_author_tbl_posts.ID AND post_meta_author_tbl_posts.post_type = 'post') AS post_meta_author_tbl ON post_meta_author_tbl.meta_key = 'author' AND post_meta_author_tbl.id = posts_post.ID WHERE 1=1 AND posts_post.post_type = 'post'
Problem solved: You can't use column aliases in the on clause. You'll have to use the real name instead - post_taxonomy_category_tbl.name. Here's a link to the stackoverflow question using my query: https://stackoverflow.com/questions/62564091/sql-error-in-mysql-query-error-unknown-column-post-taxonomy-category-in-on
Hey Craig
Great news, thanks for letting everyone know.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables