# alch\_get\_post\_meta

Function `alch_get_post_meta` allows you to get the saved meta value of a post.

For client-side use [getPostMeta](/v0.9/javascript/get_post_meta.md).

## Parameters

The function takes `$postID`, `$metaID` and optional `$default` as parameters. `$metaID` should match the `id` of some field in the [Meta Boxes `options` array](https://github.com/AlchemyOptions/docs/tree/2c13c914d733b5a3046b1cbd4bd061c75f7de117/functions/Meta-boxes.md).

## Return values

Return value can be of several types, depending on the [type of the field](/v0.9/fields.md).

**NB:** If the field is of [`editor`](/v0.9/fields/editor.md) type, the value will not be autop'ed, make sure you wrap it in [wpautop](https://developer.wordpress.org/reference/functions/wpautop/) yourself.

## Example

### In the loop

```php
if( have_posts() ) {
    while ( have_posts() ) {
        the_post();

        $postMeta = alch_get_post_meta( get_the_ID(), 'meta-id' );
    }
}
```

### Outside the loop

```php
$postMeta = alch_get_post_meta( 42, 'meta-id' );
```

### Default value

You can pass the default value as the 3rd argument.

```php
$postMeta = alch_get_post_meta( 42, 'meta-id', 'Some default value' );
```

In this case `$postMeta` will always have a value.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.alchemy-options.com/v0.9/functions/alch_get_post_meta.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
