1

I'm starting to getting along with PHP but I'm still learning, so I need some basic help.

I want to display only the value of the 'mini-description' in this array:

Array ( [0] => Array ( [name] => mini-description [value] => Suspendisse in tempus felis. [position] => 1 [is_visible] => 1 [is_variation] => 0 [is_taxonomy] => 0 ) ) 

and I'm trying to do this:

$postid = get_the_ID();
$mini = get_post_meta( $postid, '_product_attributes', array( 'mini-description' => 'value' ));
echo $mini;

But the result is: Array

Any solution? Thanks in advance.

3 Answers3

0

try

echo  $mini['mini-description']['value'];

or

echo  $mini['mini-description']->value;
isuPatches
  • 6,384
  • 2
  • 22
  • 30
0

If you need value of 'mini-description' only, you can use following code:

$mini = get_post_meta( $postid, 'mini-description', true);
echo $mini;

You need to test this in your code. Let me know if works.

In Woocommerce, you can do something like this:

$terms = get_the_terms( $productId, 'mini-description');

foreach ( $terms as $term) {
      echo $term->value;
}
Nishant Kango
  • 146
  • 1
  • 9
-2

Use

print_r($mini[0]);

or

var_dump($mini[0]);

Edit use :

$toto['mini-description']['value'];

See the difference here : php var_dump() vs print_r()

Community
  • 1
  • 1
MaximeK
  • 2,039
  • 1
  • 10
  • 16
  • If I use var_dump($mini); the result is: array(1) { ["mini-description"]=> array(6) { ["name"]=> string(16) "mini-description" ["value"]=> string(28) "Suspendisse in tempus felis." ["position"]=> string(1) "1" ["is_visible"]=> int(1) ["is_variation"]=> int(0) ["is_taxonomy"]=> int(0) } } – Borja Muñoz Jul 20 '15 at 12:35
  • I only need the value, I only want to display: Suspendisse in tempus felis. – Borja Muñoz Jul 20 '15 at 12:36
  • sorry, I'm new in stackoverflow... ;) – Borja Muñoz Jul 20 '15 at 12:47
  • you're really close to the solution! with $mini['mini-description]['value']; the result is: string(28)"Suspendisse in tempus felis." – Borja Muñoz Jul 20 '15 at 12:50
  • yes i didn't write the echo i was thinking you will replace youre $mini in the echo :) – MaximeK Jul 20 '15 at 13:02