admin管理员组文章数量:1410682
Once I've updated WordPress to version 5.3 with this error message:
[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
In category.php
code:
<?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();
?>
It also doesn't work with the Select tag:
<option value="?tag=usa" <?php if ($tag == usa) echo 'selected="selected" ';?>>Usa</option>
The only solution I made so far was to revert back to WordPress version 5.2.4.
Once I've updated WordPress to version 5.3 with this error message:
[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
In category.php
code:
<?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();
?>
It also doesn't work with the Select tag:
<option value="?tag=usa" <?php if ($tag == usa) echo 'selected="selected" ';?>>Usa</option>
The only solution I made so far was to revert back to WordPress version 5.2.4.
Share Improve this question edited Nov 17, 2019 at 14:29 Sally CJ 40.3k2 gold badges29 silver badges50 bronze badges asked Nov 17, 2019 at 1:31 KarelliKarelli 335 bronze badges 01 Answer
Reset to default 1(Revised answer, based on the code in question and this)
After the discussion, I realized that:
You should replace the
post__not_in
withtag
; i.e. use'tag' => $tag
.You should also understand that
post__not_in
should be an array of post IDs and not tag/category slugs, names, etc. And if you don't pass an array, then you'd get the error in question, even in WordPress version 5.2.4. :)You should use
get_query_var( 'tag' )
to get the selected tag (slug).And remove the
category__in
.
So your WP_Query
code would look like so:
$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 );
Additionally:
The
select
code (for letting users pick a tag):<?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>
The JavaScript code (for submitting the tag selected via the above
select
):<script type="text/javascript"> function handleSelect(elm) { window.location = elm.dataset.action.replace( '%tag%', elm.value ); } </script>
本文标签: phpError arraymap() Argument 2
版权声明:本文标题:php - Error: array_map(): Argument #2 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744996145a2636685.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论