-1

I am facing a problem that I cannot find a solution. The problem is this in below code:

$ilikiaki_omada = get_terms( array( 'taxonomy' => 'pa_ilikia', 'hide_empty' => false ) );

$omages = array();
$omages = get_field('acf_ilikiaki_omada', $ekpaideutikos_id);
$all_omades = explode(',',$omages); 

        foreach ($ilikiaki_omada as $omada) {
                    echo '<input style="margin-bottom: 0;" type="checkbox" name="ilikiaki_omada[]" value="'.$omada->name.'"';
                    if (in_array($omada->name, $all_omades)) echo ' checked ';
                    echo '/> '.$omada->name.'<br>';
         }

The problem i Face is that not checked all the same values who found!

Only checked the first value and stop!

In this example the $all_omades list has three values Where they exist in $omada->name. This is very strange. I

$all_omades is Array ( [0] => Βρέφη [1] => Νήπια [2] => Παιδιά )

$ilikiaki_omada is

 Array ( 
[0] => WP_Term Object ( [term_id] => 8335 [name] => Βρέφη [slug] => %ce%b2%cf%81%ce%ad%cf%86%ce%b7 [term_group] => 0 [term_taxonomy_id] => 8335 [taxonomy] => pa_ilikia [description] => [parent] => 0 [count] => 0 [filter] => raw ) 

[1] => WP_Term Object ( [term_id] => 8347 [name] => Νήπια [slug] => nipia [term_group] => 0 [term_taxonomy_id] => 8347 [taxonomy] => pa_ilikia [description] => [parent] => 0 [count] => 0 [filter] => raw ) 

[2] => WP_Term Object ( [term_id] => 8336 [name] => Παιδιά [slug] => %cf%80%ce%b1%ce%b9%ce%b4%ce%b9%ce%ac [term_group] => 0 [term_taxonomy_id] => 8336 [taxonomy] => pa_ilikia [description] => [parent] => 0 [count] => 2 [filter] => raw ) 

[3] => WP_Term Object ( [term_id] => 8348 [name] => Έφηβοι [slug] => efivoi [term_group] => 0 [term_taxonomy_id] => 8348 [taxonomy] => pa_ilikia [description] => [parent] => 0 [count] => 0 [filter] => raw ) 

[4] => WP_Term Object ( [term_id] => 8349 [name] => Ενήλικες [slug] => enilikes [term_group] => 0 [term_taxonomy_id] => 8349 [taxonomy] => pa_ilikia [description] => [parent] => 0 [count] => 0 [filter] => raw ) )

This is the result why dont checked Νήπια, Παιδιά but only Βρέφη!

enter image description here

For the $all_omades i have a text custom field you can see it in photo below

enter image description here

6
  • can you explain using different words? I found this difficult to understand, use the Edit link to adjust your question. Also what is an omada?
    – Tom J Nowell
    Aug 2 at 15:45
  • $omada->name is the taxonomy name ! Aug 2 at 15:54
  • in_array is a core PHP function. Is does not work any differently in WordPress. If you’re not getting the results you expect then you should log or dump the values you’re checking to confirm they are what you think they are. You could be mistaking the taxonomy name for the slug, for example. Aug 2 at 16:25
  • 1
    On a side-note, would it be easier to just use WordPress checked() function?
    – Howdy_McGee
    Aug 2 at 16:31
  • 1
    my suspicion is this is multibyte character related, if that's the case then it's a general PHP issue rather than a WordPress specific issue. It would be useful to see more of the code, specifically how $all_omades is created and where it comes from
    – Tom J Nowell
    Aug 2 at 17:51

0

Browse other questions tagged or ask your own question.