Last active
June 11, 2024 15:07
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); |
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' );
Thank you very much:-)
Hi :)
is there also a way to access repeater fields?
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' );
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 ) );
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
Hi,
I am looking the PHP code to display a specific jet engine field in a single template like there is with pods ?
<?php echo pods_field_display( 'copyright' ); ?>