doufei6456 2014-06-05 05:30
浏览 45

如何在wordpress的下拉菜单中按标题显示自定义帖子类型

i want to add a dropdown with the custom posts title, basically the code iam using shows default posts in a dropdown by title but i want to display a custom post type in a drop down any help plz here is my code

<select name="archive-dropdown"    
onchange="document.location.href=this.options[this.selectedIndex].value;">
<option value=""><?php echo esc_attr( __( 'Select Location' ) ); ?></option> 
<?php wp_get_archives( array( 'type' => 'postbypost', 'format' => 'option',  
'show_post_count' => 1) ); ?>
 </select>  
  • 写回答

1条回答 默认 最新

  • duanbi6522 2014-06-05 07:16
    关注

    try this

    <?php
    $type = 'products'; // your post type
    $args=array(
      'post_type' => $type,
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <option><?=the_title(); ?></option>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊