Created
April 18, 2019 04:57
-
-
Save shaddam/fda354cd1eea24b2de5ba26b24c7fbb8 to your computer and use it in GitHub Desktop.
How to Get Post Type in WordPress for elementor Addons
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
| /* | |
| * 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