Skip to content

Instantly share code, notes, and snippets.

@MjHead
Last active December 21, 2024 14:42
Show Gist options
  • Save MjHead/49ebe7ecc20bff9aaf8516417ed27c38 to your computer and use it in GitHub Desktop.
Save MjHead/49ebe7ecc20bff9aaf8516417ed27c38 to your computer and use it in GitHub Desktop.
Get option values for JetEngine options pages inside the PHP code
<?php
/**
* Method 1
* Can be used for: Any storage type
*
* page-slug - replace this with your Option Page slug
* option-name - replace this with your option Name/ID
*/
$value = jet_engine()->listings->data->get_option( 'page-slug::option-name' );
/**
* Method 2
* Can be used for: Any storage type
*
* page-slug - replace this with your Option Page slug
* option-name - replace this with your option Name/ID
*/
$page = jet_engine()->options_pages->registered_pages['page-slug'];
$value = $page->get( 'option-name' );
/**
* Method 3
* Can be used for: Default storage type
*
* page-slug - replace this with your Option Page slug
* option-name - replace this with your option Name/ID
*/
$all_options = get_option( 'page-slug', array() );
$value = isset( $all_options['option-name'] ) ? $all_options['option-name'] : false;
/**
* Method 4
* Can be used for: Separate storage type + `Add prefix for separate options` is DISABLED
*
* option-name - replace this with your option Name/ID
*/
$value = get_option( 'option-name' );
/**
* Method 5
* Can be used for: Separate storage type + `Add prefix for separate options` is ENABLED
*
* page-slug - replace this with your Option Page slug
* option-name - replace this with your option Name/ID
*/
$value = get_option( 'page-slug_option-name' );
@rakibulmuhajir
Copy link

what about setting the option value

@adofeg
Copy link

adofeg commented Oct 5, 2021

what about setting the option value

did you find something about set the option value?

@tongnhattruong
Copy link

Not working

@tizum
Copy link

tizum commented Feb 4, 2022

It's Working fine here, Thanks.

@AmigoDheena
Copy link

Thank you, working fine.

<?php
function jetpack_options_sc() { 
    $title = jet_engine()->listings->data->get_option( 'appoinments::service-looking-for' );
    $date = jet_engine()->listings->data->get_option( 'appoinments::date' );        
    $button = 'https://www.google.com/calendar/render?action=TEMPLATE&text='.$title.'&dates='.str_replace('-','',$date).'/'.str_replace('-','',$date);
    return $button;
}
add_shortcode('jposc', 'jetpack_options_sc');
?>

@conradomd
Copy link

What about repeater fields inside options page?

@jwamsterdam
Copy link

Hi, this code works great! Only thing, I can't get it to work with a radio selection box, retreiving the selected value. Can you share that code as wel please? many thanks!

@adofeg
Copy link

adofeg commented Nov 17, 2022

@jwamsterdam in that case you can get the radio value and then you can set the new value directly at database in wp_options , values are serialized, you can unserialize and set the value into the result array and then re-serialize and save in db

@ahmadrusli
Copy link

ahmadrusli commented Nov 19, 2022

working fine, thank you.

$counter_starter = jet_engine()->listings->data->get_option( 'commercial-invoices-settings::_counter-starter-no' );

how to update settings value from functions.php?
i want update value of "_counter-starter-no'" from functions.php on child theme.

thank you :)

@jwamsterdam
Copy link

@adofeg reading the value op mij radio buttton indeed works fine, I populate the values from a glossary list.
The returned value is the 'Field Label' though, not the 'Field Value'. Do you know how I can retreive field value?

@jwamsterdam
Copy link

Hi @adofeg The code provided works correctly. One thing though, then passing a pre-defined value in the options field, you first have to save the field in order to retreive it, otherwise it returns null.

I would like to run an action based on a change in the options page. What is the required action?
add_action('update_options', 'myFunction', 10, 3); is not working.

@Galibri
Copy link

Galibri commented Jan 26, 2023

@jwamsterdam JetEngine doesn't provide any hook to run after saving the options page, I asked them and they replied, they have no hook like this.

@Laichunw
Copy link

Laichunw commented Mar 9, 2023

@jwamsterdam @Galibri
There is some update for those who want to use php to update options.
The options inside jetengine is actually save as options in the wp_option table. So the typical get_option and update_option will do.
And the mutiple field value is saved as array.
So let say you have a option page named with slug "dining-certificate-options_copy" and the field slug is "certificate-number"
Just simply:

// getting the whole option array from wp_option
$dinning_cert_option = get_option('dining-certificate-options_copy');
//Only change the value of a item in the array
$dinning_cert_option['certificate-number'] = ' anything';
// simply update the option 
update_option('dining-certificate-options_copy', $dinning_cert_option);	

@ihslimn
Copy link

ihslimn commented Jan 29, 2024

Hooks are:

jet-engine/options-pages/after-save
jet-engine/options-pages/after-save/PAGE_SLUG
jet-engine/options-pages/updated
jet-engine/options-pages/updated/PAGE_SLUG

The only argument passed to a hook is an instance of Jet_Engine_Options_Page_Factory (\jet-engine\includes\components\options-pages\options-page.php)

@nextab
Copy link

nextab commented Sep 8, 2024

I was defining a number of modules for an overview page and then I wanted to render the modules dynamically via Ajax on click. This did not work with the jetengine object as it wasn't available during the "init" or "enqueue_scripts" action hooks.
Method 3 was the solution; I simply got the option values right out of the WordPress database.
Hope this info helps somebody else in the same situation.

@ihslimn
Copy link

ihslimn commented Dec 20, 2024

@nextab

This did not work with the jetengine object as it wasn't available during the "init" or "enqueue_scripts" action hooks.

it is not available until 'init' with priority of 12 or something like that, just try calling it a bit later

@nextab
Copy link

nextab commented Dec 21, 2024

it is not available until 'init' with priority of 12 or something like that, just try calling it a bit later

Thank you for pointing this out. I'm sure this can come in handy at some point in the future.

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