Reputation: 1706
I develop a site with wordpress and mysql. That set up is locally. On then server where I host my site(at a university) they use sqlite. I use this plugin to make wordpress work with Sqlite:
http://wordpress.org/plugins/sqlite-integration/
So far everything works fine. When I tried to execute a meta query locally everything works fine (mysql) and I get the results I expected but on server the query returns no posts.
The content is the same for both databases and the post meta's also.
CODE:
function rlp_get_posts($post_type = 'post', $num = 10, $offset = 0){
$args = array(
'posts_per_page' => $num,
'offset' => $offset,
'orderby' => 'id',
'order' => 'ASC',
'post_type' => $post_type,
'meta_query' => array(
array(
'key' => 'rlp_native_age',
'value' => array( 18, 78 ),
'type' => 'numeric',
'compare' => 'BETWEEN'
)
)
'post_status' => 'publish',
'suppress_filters' => false
);
return new WP_Query( $args );
}
WP_Query requests :
Local
[request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type = 'native' AND ((wp_posts.post_status = 'publish')) AND ( (wp_postmeta.meta_key = 'rlp_native_age' AND CAST(wp_postmeta.meta_value AS SIGNED) BETWEEN '18' AND '78') ) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date ASC LIMIT 0, 20
Server
[request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type = 'native' AND ((wp_posts.post_status = 'publish')) AND ( (wp_postmeta.meta_key = 'rlp_native_age' AND CAST(wp_postmeta.meta_value AS SIGNED) BETWEEN '18' AND '78') ) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date ASC LIMIT 0, 20
The request seems the same. For the moment I don't have access to the db to perform my own SQL queries to target the problem
EDIT
When I make a tax_query everything works fine both locally and on the server.
CODE:
function rlp_get_posts($post_type = 'post', $num = 10, $offset = 0){
$args = array(
'posts_per_page' => $num,
'offset' => $offset,
'orderby' => 'id',
'order' => 'ASC',
'post_type' => $post_type,
'tax_query' => array(
array(
'key' => 'sex',
'field' => 'id',
'terms' => array(71)
)
)
'post_status' => 'publish',
'suppress_filters' => false
);
return new WP_Query( $args );
}
WP_Query server request (same as local) :
[request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (71) ) AND wp_posts.post_type = 'native' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date ASC LIMIT 0, 20
Upvotes: 0
Views: 174
Reputation: 1706
The plugin has a bug but the author of the plugin propose a workaround until he fix it.
I tested the workaround and is working as expected.
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'rlp_native_age',
'value' => 18,
'type' => 'numeric',
'compare' => '>='
),
array(
'key' => 'rlp_native_age',
'value' => 78,
'type' => 'numeric',
'compare' => '<='
)
)
Post thread and solution :
http://wordpress.org/support/topic/wordpress-meta-query-not-working?replies=3
Upvotes: 0