0

I have some problem here with some code in Wordpress.

<?php
$output="";
foreach($type2 as $t) {$output.= "'".$t->slug."',"; }
echo $output;
?>

This code outputs this:

'cocinas','banos-y-spa','mobiliario-de-hogar',

The problem comes when I want to use $output to put it in an array:

<?php
if(is_tax( 'type', array ($output))) {
putRevSlider(get_queried_object()->slug);}
?>

The strange thing is that this one does work ok, although it's not useful, because I need it to be dynamic:

<?php
if(is_tax( 'type', array ('cocinas','banos-y-spa','mobiliario-de-hogar',))) {
putRevSlider(get_queried_object()->slug);}
?>

Why doesn't $output work inside the array if it has the same values?

1 Answer 1

1

Why are you converting array content into string.

Anyways, convert the $type2 into the format you are looking for:

<?php
$output=array();
foreach($type2 as $t) {
    $output[] =  $t->slug;
}
?>

This will provide you appropriate array which you can use directly in your is_tax() function.

<?php
if(is_tax( 'type', $output)) {
putRevSlider(get_queried_object()->slug);}
?>
Sign up to request clarification or add additional context in comments.

1 Comment

OMG! Thanks! This works fine. The reason I did it wrong is because I am not a programmer, but I am doing my best ;) Thanks

Your Answer

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