Alchemy Options Docs
v1.0
v1.0
  • Read Me
  • Installation
  • Configuration
  • Meta Boxes
  • Samples
  • Field types
    • Text
    • Password
    • URL
    • Email
    • Tel
    • Textarea
    • Editor (WYSIWYG)
    • Datepicker
    • Image upload
    • Radio buttons
    • Select
    • Checkbox
    • Colorpicker
    • Image radio
    • Post type select
    • Datalist
    • Sections
    • Repeater
    • Button group
    • Slider
    • Taxonomy select
    • Field group
  • Functions
    • alch_options_id
    • alch_network_options_id
    • alch_get_option
    • alch_get_network_option
    • alch_delete_value
    • alch_get_post_meta
  • Javascript
    • getOption
    • getNetworkOption
    • getPostMeta
  • Filters
    • alch_options_id
    • alch_default_page_capabilities
    • alch_default_page_icon
    • alch_default_page_position
    • alch_network_options_id
    • alch_options_id() . '_args'
    • alch_network_options_id() . '_args'
    • alch_allowed_editor_html_tags
    • alch_allowed_editor_protocols
    • alch_{ $optionsPageID }_capabilities
    • alch_{ $optionsPageID }_icon
    • alch_{ $optionsPageID }_position
    • alch_value_{ $optionID }
    • alch_network_value_{ $optionID }
Powered by GitBook
On this page
  • Example usage
  • Note on passing non-existent IDs
  • Params
  1. Javascript

getPostMeta

PreviousgetNetworkOptionNextFilters

Last updated 6 years ago

Function getPostMeta allows you to get the saved post meta value by passing postID and metaID parameters. Uses as a promises polyfill.

For server-side use .

Enqueue a script and . This will give you the global alchemyOptions variable.

Example usage

alchemyOptions
    .getPostMeta(42, 'my-meta-id')
    .then(value => {
        //value is a JSON string like {"success":true,"data":42}
    });

getPostMeta returns the kew defer, so you can deal with the promise later.

const myMeta = alchemyOptions.getPostMeta(42, 'my-meta-id');

//later in the code
myMeta.promise.then(value => {
    // do something with the value
});

If for some reason getPostMeta fails, you can deal with it in the fail method. It can happen if the AJAX request errored or was aborted.

alchemyOptions
    .getPostMeta(42, 'my-meta-id')
    .then(value => {
        // value is a JSON string like {"success":true,"data":42}
    })
    .fail(response => {
        // failed to get the value
    });

Note on passing non-existent IDs

Most of the time getPostMeta will be successful, even if you pass non-existent IDs to it. Consider the following example:

alchemyOptions
    .getPostMeta(121465413561, 'some-meta-id') // ID of a post that doesn't exist
    .then(value => {
        // value is a JSON string like {"success":true,"data":""}
    })

If you pass the ID of a post that doesn't exist, the call will still be successful, the data property will be an empty string.

The same thing will happen if you ask for non-existent metaID.

Params

Name

Type

Description

postID

number

Post ID to query for the meta (required)

metaID

string

Post meta ID (required)

More info can be found in the .

kew
alch_get_post_meta
add alchemy-options-client-scripts as its dependency
kew documentation