Có phải bạn muốn thiết kế website tiết kiệm chi phí và thời gian mà còn chuẩn seo ?

10/30/13

Hiển thị danh sách "post_type" trong wordpress



Hàm lấy danh sách post type theo tên post_type
<?php
        $args = array(
                                'numberposts' => 0,
                                'post_type'   => 'country-origin'
                            );
         $result = get_posts($args);                           
?>

Hàm lặp và hiển thị danh sách
<?php
     foreach($result as $row){
 ?>
<option value="<?=$row->ID?>"><?=$row->post_title?></option>
<?}?>


Ghi chú:
- $row->ID: Trả về ID
- $row->post_title: Trả về tên của post type



0 comments:

Post a Comment