2

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.

0

1 Answer 1

1

(Revised answer, based on the code in question and this)

After the discussion, I realized that:

  1. You should replace the post__not_in with tag; 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. :)

  2. You should use get_query_var( 'tag' ) to get the selected tag (slug).

  3. 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:

  1. 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>
    
  2. 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>
    
14
  • Thank you for your reply! I tested these before too but they do not work in fact posts appear but not where I want. <option value = "? tag = usa" <? php selected ($ tag, 'usa'); ? >> Usa </option> does not work in ver 5.3 As you see 'post__not_in' => '$ tag' used these items to appear only in the Category and not in the TAG selection. Example: I have some TAG "USA" when I click on the "USA" tag there I want this meta_key post to stay in Category and not appear in TAG therefore used 'post__not_in' => '$ tag' if any other solution tell me.
    – Karelli
    Commented Nov 18, 2019 at 3:32
  • Ok, let me try to understand that. If user chose that option (where tag is usa), what should happen? What posts should be displayed? What do you mean by "stay in Category"? Can you be more specific?
    – Sally CJ
    Commented Nov 18, 2019 at 3:55
  • And actually, the answer is valid for the error in the question - if you get that error, the reason is because your post__not_in value is not an array. Also, selected() does work in WP 5.3 - the function simply displays selected='selected' if the selected option is the current one in the <option>.
    – Sally CJ
    Commented Nov 18, 2019 at 4:01
  • 1
    Now it works! I'm sorry for your time! Sinrecerly
    – Karelli
    Commented Nov 18, 2019 at 6:16
  • 1
    I add meta_key work fine thanks dear
    – Karelli
    Commented Nov 18, 2019 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.