Skip to content

Instantly share code, notes, and snippets.

@MjHead
Last active June 11, 2024 15:07
Show Gist options
  • Save MjHead/5dac7f0182549b08cfc257d9ea6f14e3 to your computer and use it in GitHub Desktop.
Save MjHead/5dac7f0182549b08cfc257d9ea6f14e3 to your computer and use it in GitHub Desktop.
JetEngine. Get registered meta fields by given context - post type, taxonomy or user
<?php
/**
* Get fields for the given context and object
* Should be called on hook 'init' with priority 11 or later
*/
// Fields for Post post type
$post_fields = jet_engine()->meta_boxes->get_fields_for_context( 'post_type', 'post' );
// Fields for Product post type
$product_fields = jet_engine()->meta_boxes->get_fields_for_context( 'post_type', 'product' );
// Fields for Category taxonomy
$category_fields = jet_engine()->meta_boxes->get_fields_for_context( 'taxonomy', 'category' );
// All field groups for Users
$user_field_groups = jet_engine()->meta_boxes->get_fields_for_context( 'user' );
// All CPT fields
$cpt_fields = jet_engine()->meta_boxes->get_fields_for_context( 'post_type' );
@MjHead
Copy link
Author

MjHead commented Dec 1, 2022

Hi
You can do this in 2 ways:

  • plain WP API - echo get_post_meta( get_the_ID(), 'field_key', true );
  • with JetEngine API - echo jet_engine()->listings->data->get_meta( 'field_key' );

@WebAtelier47
Copy link

Thank you very much:-)

@markoste
Copy link

markoste commented Jul 6, 2023

Hi :)

is there also a way to access repeater fields?

@ninhvanthang
Copy link

Hi You can do this in 2 ways:

  • plain WP API - echo get_post_meta( get_the_ID(), 'field_key', true );
  • with JetEngine API - echo jet_engine()->listings->data->get_meta( 'field_key' );

Hello,
how to get field value from specify custom content type ID?
i tried this but it seem not work, 99 is ID of CCT
jet_engine()->listings->data->get_meta( 99, 'field_key' );

@AkramiPro
Copy link

jet_engine()->listings->data->get_meta( 99, 'field_key' );

use this code to get any post type meta value:

jet_engine()->listings->data->get_meta('field_key', get_post( 99 ) );

@rozuja
Copy link

rozuja commented Jun 11, 2024

Hi :)

is there also a way to access repeater fields?

Yes sir. Took me a while from this post but got it working

This is for an options page, but in single page posts works the same just extract the array in a variable

$jetfield  = jet_engine()->options_pages->registered_pages['whatsapp']; //This is my options page

$repcontactos = $jetfield->get( 'contactos' ); // This is my repeater field

Now loop over the repeater as a single $item

$item['sub field of the repeater']

<?php 

      foreach ($repcontactos as $item) { ?>
                
              <p> <?php echo $item['name'] ?> / <?php echo $item['phone'] ?></p>
     <?php }
?>

You do the rest of the HTML and PHP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment