Skip to content

Instantly share code, notes, and snippets.

@Crocoblock
Last active February 19, 2024 09:11
Show Gist options
  • Save Crocoblock/f1eba1214c0adc0a2eba609052ca790a to your computer and use it in GitHub Desktop.
Save Crocoblock/f1eba1214c0adc0a2eba609052ca790a to your computer and use it in GitHub Desktop.
Get current JetEngine listing object meta value ( somewhat similar to ACF get_field() )
<?php
//You may just use get_post_meta() to get post/term/user meta
//However, in Listing Grid, you may use get_meta() method for convenience
$value = jet_engine()->listings->data->get_meta( $meta_key, $object );
/**
* Get object meta value. Works for Posts, Terms, Users, Comments
* $object defaults to null, then the value will be retrieved from the current listing object
* Example: the current object is a Post,
* the meta key is 'age'
* the meta value is 42
*/
$value = jet_engine()->listings->data->get_meta( 'age' );
//$value is 42
/**
* To get the value from the post, different from the current listing object, pass that object as the second argument
* Example: post ID is 512
* the meta key is 'age'
* the meta value is 24
* Current listing post 'age' meta value is 48
*/
$object = get_post( 512 );
$value = jet_engine()->listings->data->get_meta( 'age', $object );
//$value is 24, as we get meta value from $object, which is a post with ID of 512
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment