Using wp_dropdown_page() to display a dropdown of a custom post type

I’m trying to create a dropdown list with the list of a certain post type.
I saw that I could use the wp_dropdown_pages function to do that.
I added this code inside my td but when the page displays the code is not interpreted. The are only few examples to look at.

<td><?php wp_dropdown_pages(array('id'=>'marque0','post_type' => 'Brands')); ?></td>

additionally I need to filter a second dropdown list which contains only child post of the parent selected in the first dropdown. To do that I need the id of the parent post. How can I get this from the element selected in the first dropdown list ?

Read More

Thanks a lot.

Update :

I found a way to go around the usage of PHP inside the wordpress page, I created shortcodes to call the wp_dropdown_pages, then I use the shortcodes inside my page.

Related posts

Leave a Reply

1 comment

  1. Surprisingly enough (!), just specify in your custom post type’s settings 'hierarchical' => true, not the hierarchical argument in wp_dropdown_pages() function.

    register_post_type( 'brands', array(
        'labels'    => array(
            ..........
        ),
        .........
        'hierarchical' => true,
        .........
    ));
    

    Then it should work:

    wp_dropdown_pages(array(
       'id' => 'marque0',
       ..........
       'post_type' => 'brands'
    ));