Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am making a search that taps into wp_query and filters thru custom taxonomy terms. It works, but I get a urlencode warning when using checkboxes to filter thru taxonomy terms assigned to POSTS, but if for example I have the taxonomy terms assigned to CUSTOM POST TYPE, I DO NOT get the warning.

I installed Development Debug Backtraces plugin to get detailed error report, but still can't solve it.

this is my code (it assumes taxonomies location location2 studio exist and have some terms assigned to them)

<?php

    /*
    Plugin Name: SS
    Plugin URI: http://wordpress.org/plugins/hello-dolly2/
    Description: Adds some search filtering
    Author: Dzimi
    Version: 1.0
    Author URI: http://ma.tt/
    */

    function vss_form() {
    $blog_url = get_bloginfo('url');
        ?>
    <form method="get" action="<?php echo $blog_url; ?>" id="ss-search" name="vkss-config">
    <input type="text" value="<?php echo 'welcome'; ?>" name="s" />
    <?php

    $taxes = array('location', 'location2', 'studio');

    foreach ($taxes as $taxonomy) {

        // echo gettype($taxonomy);

        $terms = get_terms($taxonomy, array('orderby' => 'id', 'order' => 'ASC'));
        foreach ($terms as $term) {
            //

            //

            $term_name = $term->name;
            echo "<p><input type=\"checkbox\" name=\"{$taxonomy}[]\" value=\"$term_name\" id=\"$term_name\" /><label for=\"$term_name\"> $term_name</label></p>";
        }
    }

    ?>
    <button>SS Submit</button>
    </form>
    <?php
    }

    function vss_search($query) {

        // has the form been init?
        if (isset($_GET['s'])) {

            //make the query
            $s = filter_input(INPUT_GET, 's', FILTER_SANITIZE_STRING);
            // if ( empty( $s ) ) return;
            $query->is_search = true;
            $query->set( 's', $s );    

            $tax_holder = array();

            $all_taxes = array('location', 'location2', 'studio');

            $tax_names_holder = array();

            foreach ($all_taxes as $ind_tax_name) {

                if (isset($_GET[$ind_tax_name])) {

                    $cb_tax_name = $_GET[$ind_tax_name];

                    $tax_names_holder[$ind_tax_name] = $cb_tax_name;

                    // echo '<pre>';
                    // print_r($tax_names_holder);
                    // echo '</pre>';
                }

            } // end foreach

            foreach ($tax_names_holder as $key => $value) {

                if (isset($_GET[$key])) {

                    $get_tax_term = $_GET[$key];

                    unset($tax_term);
                    foreach ($_GET[$key] as $value) {
                        $tax_term .= ','.$value;
                    }

                    $tax_term = ltrim($tax_term, ',');

                    $new_tax_term = explode(',', $tax_term);

                    $tax_holder[] = array(
                    'taxonomy' => $key,
                    'field' => 'slug',
                    'operator' => 'AND',
                    'terms' => $new_tax_term
                    );


                } // end if (isset($_GET[$key])) {

            } // end foreach
            // end get tax checkbox results

            $query->set( 'tax_query', $tax_holder); 
            // echo '<pre>';
            // print_r($tax_holder);
            // echo '</pre>';

        } // end has the form been init?

    } // end vss_search()
    add_action('pre_get_posts', 'vss_search');


    add_shortcode('vss', 'vss_form');
    ?>

And this is the detailed error:

#0  error_backtrace(2, urlencode() expects parameter 1 to be string, array given, C:\wamp\www\plugin_tester\wp-includes\formatting.php, 3645, Array ([path] => Array ([0] => bg),[suffix] => ))
#1  urlencode(Array ([0] => bg)) called at [C:\wamp\www\plugin_tester\wp-includes\formatting.php:3645]
#2  wp_basename(Array ([0] => bg)) called at [C:\wamp\www\plugin_tester\wp-includes\query.php:1749]
#3  WP_Query->parse_tax_query(Array ([s] => welcome,[location] => Array ([0] => bg),[error] => ,[m] => ,[p] => 0,[post_parent] => ,[subpost] => ,[subpost_id] => ,[attachment] => ,[attachment_id] => 0,[name] => ,[static] => ,[pagename] => ,[page_id] => 0,[second] => ,[minute] => ,[hour] => ,[day] => 0,[monthnum] => 0,[year] => 0,[w] => 0,[category_name] => ,[tag] => ,[cat] => ,[tag_id] => ,[author] => ,[author_name] => ,[feed] => ,[tb] => ,[paged] => 0,[comments_popup] => ,[meta_key] => ,[meta_value] => ,[preview] => ,[sentence] => ,[fields] => ,[menu_order] => ,[category__in] => Array (),[category__not_in] => Array (),[category__and] => Array (),[post__in] => Array (),[post__not_in] => Array (),[tag__in] => Array (),[tag__not_in] => Array (),[tag__and] => Array (),[tag_slug__in] => Array (),[tag_slug__and] => Array (),[post_parent__in] => Array (),[post_parent__not_in] => Array (),[author__in] => Array (),[author__not_in] => Array ())) called at [C:\wamp\www\plugin_tester\wp-includes\query.php:1577]
#4  WP_Query->parse_query() called at [C:\wamp\www\plugin_tester\wp-includes\query.php:2152]
#5  WP_Query->get_posts() called at [C:\wamp\www\plugin_tester\wp-includes\query.php:3243]
#6  WP_Query->query(Array ([s] => welcome,[location] => Array ([0] => bg))) called at [C:\wamp\www\plugin_tester\wp-includes\class-wp.php:541]
#7  WP->query_posts() called at [C:\wamp\www\plugin_tester\wp-includes\class-wp.php:605]
#8  WP->main() called at [C:\wamp\www\plugin_tester\wp-includes\functions.php:808]
#9  wp() called at [C:\wamp\www\plugin_tester\wp-blog-header.php:14]
#10 require(C:\wamp\www\plugin_tester\wp-blog-header.php) called at [C:\wamp\www\plugin_tester\index.php:17]
share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.