• //Sorry for my English.
    I have a function which returns an array:

    function isset_municipio_vars(){
    	if(isset($_SESSION['municipio_vars'])){
    		$municipio_vars = $_SESSION['municipio_vars'];//This is an array with values:name,address,phone,etc..   
    	}else{
    		echo "MUNICIPIO_VARS no existe";
    	}
    	return $municipio_vars;
    }
    add_shortcode('isset_municipio_vars', 'isset_municipio_vars');

    What can I do to use it in different block text?
    Three different block text:

    Name: [isset_municipio_vars $municipio_vars->NAME]
    Adress: [isset_municipio_vars $municipio_vars->ADRESS]
    Phone: [isset_municipio_vars $municipio_vars->PHONE]
    ...

    I known that this is wrong but it is the idea.

    I just got this:

    function isset_municipio_vars(){
    	if(isset($_SESSION['municipio_vars'])){
    		$municipio_vars = $_SESSION['municipio_vars'];//This is an array with values:name,address,phone,etc..   
    	}else{
    		echo "MUNICIPIO_VARS no existe";
    	}
    	return $municipio_vars->NAME;
    }
    add_shortcode('isset_municipio_vars', 'isset_municipio_vars');

    One only value:
    Name: [isset_municipio_vars] //This return the name

    Thanks for your attention,
    Regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m not sure what you really have in the array, but try this:
    return "{$municipio_vars->NAME}<br>\r{$municipio_vars->ADRESS}<br>\r{$municipio_vars->PHONE}<br>\r";

    A more generic solution for an array of any size:

    $content = '';
    foreach ( $municipio_vars as $line ) {
       $content .= "$line<br>\r";
    }
    return $content;

    BTW, never echo anything from a shortcode handler. You could change your echo line to this:
    return 'MUNICIPIO_VARS no existe';

    • This reply was modified 7 years, 1 month ago by bcworkz. Reason: fix code block 2
    Thread Starter desarrollo1

    (@desarrollo1)

    Thanks bcworkz, but I need other thing, I’ll have to do it another way.
    Yes, I know, I know. I used echo just to try.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to insert values of array in different block text.’ is closed to new replies.