admin管理员组文章数量:1130349
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>
<?php
$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";
} ?>
</select>
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>
<?php
$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";
} ?>
</select>
Share
Improve this question
asked Dec 18, 2018 at 3:39
lushiris02lushiris02
357 bronze badges
1 Answer
Reset to default 1Found 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.)
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>
<?php
$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";
} ?>
</select>
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>
<?php
$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";
} ?>
</select>
Share
Improve this question
asked Dec 18, 2018 at 3:39
lushiris02lushiris02
357 bronze badges
1 Answer
Reset to default 1Found 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.)
本文标签: loopCreating select dropdown with parentlevel custom post types
版权声明:本文标题:loop - Creating select dropdown with parent-level custom post types 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749088855a2314201.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论