DB Error: Unknown column in ‘on clause’
-
Hi,
I’m executing quite simple find function:
$my_pod = pods( 'my_pod' ); $params = array( 'limit' => 1, 'where' => ' simple_relationship_field_1.meta_value = "' . pods_sanitize( 'value_1' ) . '" AND simple_relationship_field_2.meta_value = "' . pods_sanitize( 'value_2' ) . '" ' ); $my_pod->find( $params ); if ( $my_pod->total() > 0 ) { while ( $my_pod->fetch() ) { echo $my_pod->field('ID'); } }
As a result it throws a Database error:
Database Error : [Unknown column ‘simple_relationship_field_2.post_id’ in ‘on clause’]
SELECT DISTINCT
t
.* FROMwpbf20_posts
ASt
LEFT JOINwpbf20_postmeta
ASsimple_relationship_field_1
ONsimple_relationship_field_1
.meta_key
= ‘simple_relationship_field_1’ ANDsimple_relationship_field_1
.post_id
=t
.ID
LEFT JOINwpbf20_postmeta
ASsimple_relationship_field_2_meta_value
ONsimple_relationship_field_2_meta_value
.meta_key
= ‘meta_value’ ANDsimple_relationship_field_2_meta_value
.post_id
=simple_relationship_field_2
.post_id
LEFT JOINwpbf20_postmeta
ASsimple_relationship_field_2
ONsimple_relationship_field_2
.meta_key
= ‘simple_relationship_field_2’ ANDsimple_relationship_field_2
.post_id
=t
.ID
WHERE ( (simple_relationship_field_1
.meta_value
= ‘value_1’ ) AND (simple_relationship_field_2
.meta_value
= ‘value_2’ ) AND (t
.post_type
= “my_pod” ) AND (t
.post_status
IN ( “publish” ) ) ) ORDER BYt
.menu_order
,t
.post_title
,t
.post_date
LIMIT 0, 1Database Error; SQL: SELECT DISTINCT
t
.* FROMwpbf20_posts
ASt
LEFT JOINwpbf20_postmeta
ASsimple_relationship_field_1
ONsimple_relationship_field_1
.meta_key
= ‘simple_relationship_field_1’ ANDsimple_relationship_field_1
.post_id
=t
.ID
LEFT JOINwpbf20_postmeta
ASsimple_relationship_field_2_meta_value
ONsimple_relationship_field_2_meta_value
.meta_key
= ‘meta_value’ ANDsimple_relationship_field_2_meta_value
.post_id
=simple_relationship_field_2
.post_id
LEFT JOINwpbf20_postmeta
ASsimple_relationship_field_2
ONsimple_relationship_field_2
.meta_key
= ‘simple_relationship_field_2’ ANDsimple_relationship_field_2
.post_id
=t
.ID
WHERE ( (simple_relationship_field_1
.meta_value
= ‘value_1’ ) AND (simple_relationship_field_2
.meta_value
= ‘value_2’ ) AND (t
.post_type
= “my_pod” ) AND (t
.post_status
IN ( “publish” ) ) ) ORDER BYt
.menu_order
,t
.post_title
,t
.post_date
LIMIT 0, 1; Response: Unknown column ‘simple_relationship_field_2.post_id’ in ‘on clause’However I can perform similar query using WP_Query and it does work with no issues:
$my_query = new WP_Query( array( 'post_type' => array('my_pod'), 'meta_query' => array( array( 'key' => 'simple_relationship_field_1', 'value' => pods_sanitize( 'value_1' ), 'compare' => '=' ), array( 'key' => 'simple_relationship_field_2', 'value' => pods_sanitize( 'value_2' ), 'compare' => '=' ), ) ) ); while ( $my_query->have_posts() ) : $my_query->the_post(); echo get_the_id() . '<br/>'; endwhile;
What may cause an issue?
Thank you
- You must be logged in to reply to this topic.