关于sqlite的Wordpress元查询无法正常工作

时间:2014-05-08 16:29:42

标签: mysql wordpress sqlite

我用wordpress和mysql开发一个网站。那个设置在当地。在我托管我的网站(在大学)的服务器上,他们使用sqlite。我使用这个插件使wordpress与Sqlite一起工作:

http://wordpress.org/plugins/sqlite-integration/

到目前为止一切正常。当我尝试在本地执行元查询时,一切正常(mysql),我得到了我期望的结果但在服务器上查询没有返回任何帖子。

两个数据库和后期元素的内容相同。

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请求:

本地

[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

服务器

[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

请求似乎是一样的。目前我无法访问数据库以执行我自己的SQL查询来定位问题

修改

当我进行tax_query时,一切都在本地和服务器上正常工作。

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服务器请求(与本地相同):

[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

1 个答案:

答案 0 :(得分:0)

该插件有一个错误,但该插件的作者提出了一个解决方法,直到他修复它。

我测试了解决方法,并按预期工作。

'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' => '<='
    )
)

发布帖子和解决方案:

http://wordpress.org/support/topic/wordpress-meta-query-not-working?replies=3