Skip to content

Instantly share code, notes, and snippets.

@MjHead
Last active October 5, 2020 07:50
Show Gist options
  • Save MjHead/96e23515e5cda0a1fdec224d5fa0ed9d to your computer and use it in GitHub Desktop.
Save MjHead/96e23515e5cda0a1fdec224d5fa0ed9d to your computer and use it in GitHub Desktop.
Get Custom Content Type items from the code
<?php
/**
This function should be called on the 'init' hook with priority 11 or later,
if not custom content type instances will not be registered yet
Available operators:
=
!=
>
>=
<
<=
LIKE
NOT LIKE
IN
NOT IN
BETWEEN
NOT BETWEEN
Available types:
auto
integer
float
timestamp
date
char
*/
function my_get_cct_items( $type = null, $args = array() ) {
if ( ! $type ) {
return array();
}
if ( ! class_exists( '\Jet_Engine\Modules\Custom_Content_Types\Module' ) ) {
return array();
}
$module = \Jet_Engine\Modules\Custom_Content_Types\Module::instance();
$type_instance = $module->manager->get_content_types( $type );
if ( ! $type_instance ) {
return array();
}
return $type_instance->db->query( $args );
}
add_action( 'init', function() {
$items = my_get_cct_items( 'form_submissions', array(
array(
'field' => 'email',
'operator' => '=',
'value' => '[email protected]',
'type' => 'auto',
),
) );
}, 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment