0

I'm trying to display dropdown menu with posts with custom "post_type".

In case I insert this code, it shows dropdown menu with all "pages".

$arg=array(
            'show_option_none' => __( 'None' ),
            'orderby' => 'title',
            'hide_empty' => false,
            'suppress_filters' => true
        );

        wp_dropdown_pages($arg);

But in case I insert this code, it doesn't show nothing, neither dropdown menu at all.

$arg=array(
            'show_option_none' => __( 'None' ),
            'orderby' => 'title',
            'hide_empty' => false,
            'post_type'=>'custom_post_type',
            'suppress_filters' => true
        );

        wp_dropdown_pages($arg);

Thanks for any advice!!

WordPress 3.9.2, PHP 5.5.1

  • The name of your custom post type is 'custom_post_type'? – Gabriel Aug 31 '14 at 19:47
  • No. The name of my custom post type is 'events'. But it doesn't matter. But if I use any post type (include default 'post') it doesn't work. Just if I use 'post_type' argument it's not working. – user2790605 Aug 31 '14 at 20:21
  • 1
    Is your post type hierarchical? – Steven Jones Aug 31 '14 at 20:44
  • 2
    Yep, that was problem! My post_type wan't hierarchical. After set 'hierarchical' => true, it works! Thank you Steven Jones. – user2790605 Aug 31 '14 at 21:21
6

As answered by Steven Jones in the comments, I just want to confirm that the key thing is to specify your custom post type's settings to be 'hierarchical' => true, not the hierarchical argument in wp_dropdown_pages function.

If you are using a custom plugin like Types or CPT UI, just set the option to true.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.