Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save shaddam/fda354cd1eea24b2de5ba26b24c7fbb8 to your computer and use it in GitHub Desktop.

Select an option

Save shaddam/fda354cd1eea24b2de5ba26b24c7fbb8 to your computer and use it in GitHub Desktop.
How to Get Post Type in WordPress for elementor Addons
/*
* Get Post Type
* return array
*/
function igroup_get_post_types( $args = [] ) {
$post_type_args = [
'show_in_nav_menus' => true,
];
if ( ! empty( $args['post_type'] ) ) {
$post_type_args['name'] = $args['post_type'];
}
$_post_types = get_post_types( $post_type_args , 'objects' );
$post_types = [];
foreach ( $_post_types as $post_type => $object ) {
$post_types[ $post_type ] = $object->label;
}
return $post_types;
}
// paste this code on elementor widget
$this->add_control(
'post_type_slider',
[
'label' => esc_html__( 'Post Sourse', 'igroup' ),
'type' => Controls_Manager::SELECT2,
'label_block' => false,
'options' => igroup_get_post_types(),
]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment