How to find meta_values to call

On the post edit screen you can have the »Custom Fields« meta box, looking somewhat like shown here. You might have to enable it via the screen options. This way you can see the meta data for the edited post, but underscored meta data won’t be shown, because it is hidden. To make the hidden meta visible during development put this into your functions.php:

    function unprotected_meta( $protected, $meta_key ) {
        $protected = ( '-' == $meta_key[0] );
        return $protected;
    }
    add_filter( 'is_protected_meta', 'unprotected_meta', 10, 2 );

As for a function you can use to get all the post meta, there is get_post_custom(), which

Returns a multidimensional array with all custom fields of a particular post or page.

For getting just keys use get_post_custom_keys() and for values there is get_post_custom_values() available.


Edit: in response to comment

If you want to query for taxonomies you should take a look into

As you’re talking about archives you might want to take a look at templates

because you can have one for taxonomies.

Product attributes are saved by woocommerce as taxonomy, thereby prefixing the taxonomy name with pa_, e.g. pa_room-size. If you want to get the attributes for a product you could it via post meta:

$product_attributes_pm = get_post_meta( get_the_ID(), '_product_attributes' );
echo '<pre>';
print_r($product_attributes_pm);
echo '</pre>';

Or you use the woocommerce function get_attributes():

global $product;
$product_attributes_wcf = $product->get_attributes();
echo '<pre>';
print_r($product_attributes_wcf);
echo '</pre>';

Or you can get the information directly from the $product object:

global $product;
$product_attributes_obj = maybe_unserialize( array_shift( $product->product_custom_fields['_product_attributes'] ) );
echo '<pre>';
print_r($product_attributes_obj);
echo '</pre>';

Hope that helps and gives you a little bit deeper insight on how to proceed in your case.

Leave a Comment