404 if I put an integer in the option value element(HTML select)

I’m trying to make a query filtered with some dropdowns, so I’m using select - option element from HTML. The problem is that if I put an integer in the value, it redirects me to the 404 page, with a string it’s OK.

This is with a string and the var dump on the $_POST

echo '<option value="australia">' . $country->name . '</option>';
var_dump: array(1) { ["festivals_categories"]=> string(9) "australia" }

This loads 404.php
echo '<option value="10">' . $country->name . '</option>';

I need to use integers there.
Any ideas?

I assume you have a page called Australia but do you have a page called 10?

Otherwise you need to show your code where you are reciving the option.

Thank you for your response.

I will add my code because it will explain the situation much better.
It will make no difference if I would delete the php from the form.

<form  method="post" action="">

  <select name="festivals_categories">';
    <option>All Countries</option>'

    <?php
    $countries = get_terms( array(
      'taxonomy' => 'festivals_categories',
      'parent' => 8,
      'hide_empty' => true
    ) );

    foreach ($countries as $country) {
     if($country->count >= 1){


      echo '<option value="australia">' . $country->name . '</option>';

     }
   }
    ?>
  </select>
 <input type="submit"/>
</form>
<?php 
var_dump($_POST);
 die();

?>

Apparently that was not the problem.

@Rubble do you mind helping me concatenate json in the option value?

echo '<option value="{"parent":' . $country->parent .', "term_id":' . $country->term_id .'}">' . $country->name . '</option>';

I think the json is the real problem, the integer in the value and the error was my mistake, I thought that was the problem but it is not.

LE:I really not expecting for someone else to just resolve my problems, I really struggled with this the hole day but I failed to find a solution.

Sorry @vlrstea I would not know where to start. If I were you I would start with one bit at a time as you will see what it displays in the html code.

I’m a bit confused. If using the variable $country->name is working correctly, I don’t understand why you are not using the variable $country->parent or whatever it is you need there. Using what looks to be a JSON object as an attribute value like that does not look correct to me.

I’m trying to make a page where I could filter(with a dropdown) the posts based on two(different) taxonomies terms.
My taxonomies are like this:

-taxonomy
  -term
    -subterm < based on this  I want to filter

first taxonomy
-festival_categories
  -countries
    -germany (I want to filter only based on the countries)
    -france
    -italy
  -cities
    -berlin
    -paris
    -rome

second taxonomy
-festival_date
  -year
    -2018 
    -2019
  -month
    -january (I want to filter only based on the month)
    -february
    -march

This redirects me to 404.php, probably because the path(defined in option's value) is not valid. Or I am wrong?
The query is simple, I managed to filter something static(see the array commented in the code), but I can’t make it to filter by a dropdown.

form  method="GET" action="">
  <select name="festivals_categories">
    <option value="">All Countries</option>

    <?php
    $separator = "|";
    $countries = get_terms( array(
      'taxonomy' => 'festivals_categories',
      'parent' => 8,
      'hide_empty' => true
    ) );

    foreach ($countries as $country) {

      ?>
    <option value='<?php echo $country->parent . $separator . $country->slug; ?>'>
        <?php echo $country->name;?>  
    </option> 

    <?php
}
?>
</select>

<select name="festival_date">
  <option>All months</option>
  <?php
  $months = get_terms( array(
    'taxonomy' => 'festival_date',
    'parent' => 33,
    'hide_empty' => true
  ) );

  foreach ($months as $month) {

    ?>
    <option value='<?php echo $month->parent . $separator . $month->slug; ?>'>
        <?php echo $month->name;?>   
    </option> 


  <?php
}
?>

</select>
<input type="submit"/>
</form>
<?php 


$list = array();
$item = array(); 

die(); 
foreach($_GET as $key => $value){

  if($value != ''){
    $value = explode("|", $value);
    
    $item['taxonomy'] = htmlspecialchars($key);
    $item['field'] = $value[0];
    $item['terms'] = $value[1];
    $list[] = $item;
  }       
}  
$cleanArray = array_merge( $list );

$args['post_type'] = 'festival';
$args['showposts'] = -1;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args['paged'] = $paged;  
$args['tax_query'] = $cleanArray; 

// $args = array(
//   'post_type' => 'festival',
//   'posts_per_page' => -1,
//   'tax_query' => array(
//     array(
//       'taxonomy' => 'festivals_categories',
//       'field'    => 8, <- taxonomy term($country->parent)
//       'terms'    => 13, <- taxonomy subterm($country->slug(here is actually $country->term_id))
//     ),
//     // array(
//     //   'taxonomy' => 'festival_date',
//     //   'field'    => 29,
//     //   'terms'    => 30,
//     // ),
//   ),
// );


echo '<pre>';
var_dump($args);
die();
$the_query = new WP_Query( $args );

?>

<?php echo ($the_query->found_posts > 0) ? '<h3 class="foundPosts">' . $the_query->found_posts. ' listings found</h3>' : '<h3 class="foundPosts">We found no results</h3>';?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post();

the_title(); ?> </br> <?php

endwhile; wp_reset_postdata();?> 

@Mittineague You are correct, I changed the code.
$country->name displays the taxonomy subterm(germany, italy…etc), it needs to display the name so it can be chosen in the dropdown, the $country->parent is the term(countries), I need it in the query. I edited the commented $args array so you could understand better.

@Rubble Thank you very much.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.