I'm trying to create a dropdown with an option for each top-level parent. I've gotten the query down because when I print the results, I see the posts I'm looking for. My code is also creating the right number of options, but it's not entering the info as I'd expect. Here is the code I have:

<select class="filters-select">
    <option value="*">Show All</option>
        $args = array(
            'post_type' => 'locations',
            'post_status' => 'publish',
            'order_by' => 'title',
            'order' => 'asc',
            'post_parent' => 0,
            'posts_per_page' => -1
        $posts = get_posts( $args );
        foreach ( $posts as $post ) {
            echo "<option value='." . $post->slug . "' class='" . $post->slug . "'>" . $post->name . "</option>\n";
        } ?>                

1 Answer 1


Found the answer. I was using the terms nomenclature to call my info. Had to update to:

echo "<option value='." . $post->post_name . "'>" . $post->post_title . "</option>\n";

And now it's working just fine. (I also eliminated class cause I didn't need it here.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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