skip to Main Content

How can i display custom post type posts list in elementor select control

This is my code =>
I have used this but this shows post categories not post title

$options = array();

    $posts = get_posts( array(
        'post_type'  => 'digital_card'
    ) );

    foreach ( $posts as $key => $post ) {
setup_postdata( $post );
$options[$post->ID] = get_the_title();
    }
    
        
        $this->add_control(
            'show_elements',
            [
                'label' => __( 'Select Posts', 'plugin-domain' ),
                'label_block' => ('bool'),
                'type' => ElementorControls_Manager::SELECT,
                'multiple' => true,
                'options' => $options,
                
            ]
        );

2

Answers


  1. Try the below code.

    $options = array();
    
    $posts = get_posts( array(
        'post_type'  => 'digital_card'
    ) );
    
    foreach ( $posts as $key => $post ) {
        $options[$post->ID] = get_the_title($post->ID);
    }
    
    Login or Signup to reply.
  2.     public static function getLocations()
        {
            $posts = get_posts(array('post_type' => 'location'));
            $allPosts = array();
            foreach ($posts as $key => $post) {
    
                array_push(
                        $allPosts,
                        array(
                                'map_latitude'  => $post->post_author,
                                'pin_title'     => $post->post_title,
                        )
                );
    
            }
    
            return $allPosts;
        }
    
    
    $this->add_control(
                    'id',
                    array(
                            'label'       => __('Location Map Pins', 'textdomain'),
                            'type'        => Controls_Manager::REPEATER,
                            'default'     => Hip_Maps_Elementor_Widget::getLocations(),
                            'fields'      => $repeater->get_controls(),
                            'title_field' => '{{{ pin_title }}}',
                            'prevent_empty' => false,
                            
                    )
            );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search