一旦我用以下错误消息将WordPress更新到5.3版:
[17-Nov-2019 01:15:14 UTC] PHP Warning: array_map(): Argument #2 should be an array in /home/name/public_html/web/wp-includes/class-wp-query.php on line 2069
[17-Nov-2019 01:15:14 UTC] PHP Warning: implode(): Invalid arguments passed in /home/name/public_html/web/wp-includes/class-wp-query.php on line 2069
[17-Nov-2019 01:15:14 UTC] WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near \') AND (
wpuw_term_relationships.term_taxonomy_id IN (9)
) AND (
wpuw_postm\' at line 1 for query SELECT SQL_CALC_FOUND_ROWS wpuw_posts.ID FROM wpuw_posts LEFT JOIN wpuw_term_relationships ON (wpuw_posts.ID = wpuw_term_relationships.object_id) INNER JOIN wpuw_postmeta ON ( wpuw_posts.ID = wpuw_postmeta.post_id ) WHERE 1=1 AND wpuw_posts.ID NOT IN () AND (
wpuw_term_relationships.term_taxonomy_id IN (9)
) AND (
wpuw_postmeta.meta_key = \'ecpt_toparticle\'
) AND wpuw_posts.post_type = \'post\' AND (wpuw_posts.post_status = \'publish\' OR wpuw_posts.post_status = \'private\') GROUP BY wpuw_posts.ID ORDER BY wpuw_posts.post_date DESC LIMIT 0, 5 made by require(\'wp-blog-header.php\'), require_once(\'wp-includes/template-loader.php\'), include(\'/themes/mydesign/category.php\'), WP_Query->__construct, WP_Query->query, WP_Query->get_posts
在中
category.php
代码:
<?php
$args = array(
\'meta_key\'=> \'ecpt_toparticle\',
\'showposts\' => 5,
\'category__in\' => $cat,
\'post__not_in\' => $tag
);
$sticky_query = new WP_Query( $args );
while ( $sticky_query->have_posts() ) : $sticky_query->the_post();
?>
它也不适用于Select标记:
<option value="?tag=usa" <?php if ($tag == usa) echo \'selected="selected" \';?>>Usa</option>
到目前为止,我唯一的解决方案是恢复到WordPress版本5.2.4。
最合适的回答,由SO网友:Sally CJ 整理而成
(修订答案,基于问题代码和this)
经过讨论,我意识到:
您应该更换post__not_in
具有tag
; i、 e.使用\'tag\' => $tag
.
你也应该明白post__not_in
应该是array 如果不传递数组,那么即使在WordPress版本5.2.4中,也会出现问题。:)
您应该使用get_query_var( \'tag\' )
获取所选标记(slug)。
然后拆下category__in
.
因此,您的WP_Query
代码如下所示:
$args = array( // then the query args
\'posts_per_page\' => 5, // you should use posts_per_page and not showposts
\'post_type\' => \'post\',
\'tag\' => get_query_var( \'tag\' )
);
$sticky_query = new WP_Query( $args );
此外:
在select
代码(用于让用户选择标记):
<?php $tag = get_query_var( \'tag\' ); ?>
<select name="formal" class="city-choice" onchange="handleSelect(this)"
data-action="<?php echo esc_url( add_query_arg( \'tag\', \'%tag%\' ) ); ?>">
<option value="">Select a tag</option>
<option value="usa" <?php selected( $tag, \'usa\' ); ?>>Usa</option>
<option value="italy" <?php selected( $tag, \'italy\' ); ?>>Italy</option>
</select>
JavaScript代码(用于提交通过上述select
):<script type="text/javascript">
function handleSelect(elm) {
window.location = elm.dataset.action.replace( \'%tag%\', elm.value );
}
</script>