LEFT JOIN `wp_term_relationships` AS `rel_term2` ON `rel_term2`.`object_id` = `t`.`ID`
INNER JOIN `wp_term_taxonomy` AS `rel_tt_term2` ON `rel_tt_term2`.`taxonomy` = '".$pageTerms->taxonomy."' AND `rel_tt_term2`.`term_taxonomy_id` = `rel_term2`.`term_taxonomy_id`
LEFT JOIN `wp_terms` AS `".$pageTerms->taxonomy."` ON `".$pageTerms->taxonomy."`.`term_id` = `rel_tt_term2`.`term_id`
";
$and="
AND `".$pageTerms->taxonomy."`.`term_id` = ".$pageTerms->term_id
// LEFT JOIN `wp_term_relationships` AS `rel_term2` ON `rel_term2`.`object_id` = `t`.`ID`
// LEFT JOIN `wp_term_taxonomy` AS `rel_tt_term2` ON `rel_tt_term2`.`taxonomy` = 'city' AND `rel_tt_term2`.`term_taxonomy_id` = `rel_term2`.`term_taxonomy_id`
// LEFT JOIN `wp_terms` AS `city` ON `city`.`term_id` = `rel_tt_term2`.`term_id`
// WHERE ( ( `valid`.`meta_value` > "2019-05-29" AND `field`.`term_id` = 297 AND `city`.`term_id` = 285 ) AND ( `t`.`post_type` = "job" ) AND ( `polylang_languages`.`object_id` IS NOT NULL ) AND ( `t`.`post_status` IN ( "publish" ) ) )
// WHERE ( ( `valid`.`meta_value` > "2019-05-29" AND `field`.`term_id` = 297 ) AND ( `t`.`post_type` = "job" ) AND ( `polylang_languages`.`object_id` IS NOT NULL ) AND ( `t`.`post_status` IN ( "publish" ) ) )
$condition=($term&&$termID)?" AND `".$term."`.`term_id` = ".$termID:'';
$structure=($term&&$termID)?" LEFT JOIN `wp_term_relationships` AS `rel_term2` ON `rel_term2`.`object_id` = `t`.`ID`
INNER JOIN `wp_term_taxonomy` AS `rel_tt_term2` ON `rel_tt_term2`.`taxonomy` = '".$term."' AND `rel_tt_term2`.`term_taxonomy_id` = `rel_term2`.`term_taxonomy_id`
LEFT JOIN `wp_terms` AS `".$term."` ON `".$term."`.`term_id` = `rel_tt_term2`.`term_id` ":'';
$sql="SELECT * FROM (SELECT term.name, count(*) as total, CAST(`termmeta`.`meta_value` as INT) as no, `termpage`.`meta_value` as pageID, `term`.`term_id` as termID, `pages`.`post_title` as title
$sql="SELECT * FROM (SELECT term.name, count(*) as total, CAST(`termmeta`.`meta_value` as INT) as no, `termpage`.`meta_value` as pageID, `term`.`term_id` as termID, `pages`.`post_title` as title, `pages`.`post_status` as status
FROM `{$prefix}posts` AS `t`
LEFT JOIN `{$prefix}postmeta` AS `valid` ON `valid`.`meta_key` = 'valid' AND `valid`.`post_id` = `t`.`ID`
...
...
@@ -832,29 +789,11 @@ function getRecords($taxonomy) {
LEFT JOIN `{$prefix}termmeta` AS `termmeta` ON termmeta.term_id = term.term_id AND termmeta.meta_key = 'order'
LEFT JOIN `{$prefix}termmeta` AS `termpage` ON termpage.term_id = term.term_id AND termpage.meta_key = 'page-id'
LEFT JOIN `{$prefix}posts` AS `pages` ON `pages`.`ID` = `termpage`.`meta_value`
{$additional}
{$structure}
LEFT JOIN `{$prefix}term_relationships` AS `polylang_languages` ON `polylang_languages`.`object_id` = `t`.`ID` AND `polylang_languages`.`term_taxonomy_id` = $langID
WHERE ( ( `valid`.`meta_value` >= '{$today}' {$and} ) AND ( `t`.`post_type` = 'job' ) AND ( `polylang_languages`.`object_id` IS NOT NULL ) AND ( `t`.`post_status` IN ( 'publish' ) ) )
WHERE ( ( `valid`.`meta_value` >= '{$today}' {$condition} ) AND ( `t`.`post_type` = 'job' ) AND ( `polylang_languages`.`object_id` IS NOT NULL ) AND ( `t`.`post_status` IN ( 'publish' ) ) )
// WHERE ( ( `valid`.`meta_value` > "2019-05-29" AND `field`.`term_id` = 297 ) AND ( `t`.`post_type` = "job" ) AND ( `polylang_languages`.`object_id` IS NOT NULL ) AND ( `t`.`post_status` IN ( "publish" ) ) )