Skip to content

Instantly share code, notes, and snippets.

@stnc
Created September 15, 2017 19:16
Show Gist options
  • Save stnc/e6a505ed631754c74523bc57ef5dbccc to your computer and use it in GitHub Desktop.
Save stnc/e6a505ed631754c74523bc57ef5dbccc to your computer and use it in GitHub Desktop.
wordpress kategorileri listemeleme yontemleri
<?php
//yontem 1 dropdown olarak getirir
$args = array(
'show_option_all' => '',
'show_option_none' => '',
'option_none_value' => '-1',
'orderby' => 'ID',
'order' => 'ASC',
'show_count' => 0,
'hide_empty' => 1,
'child_of' => 0,
'exclude' => '',
'include' => '',
'echo' => 0,
'selected' => 1,
'hierarchical' => 1,
'name' => 'cat',
'id' => '',
'class' => 'postform',
'depth' => 0,
'tab_index' => 0,
'taxonomy' => 'mp-event_category',
'hide_if_empty' => false,
'value_field' => 'term_id',
);
// print_r(wp_dropdown_categories( $args));
// die;
//yontem 2 listeli olarak getirir
$root_categories = get_categories(
array(
'taxonomy' => 'mp-event_category' ,
'post_type' => 'mp-event' ,
'hierarchical' => true,
)
);
$newResult = array();
foreach($root_categories as $key => $value)
{
$newResult[] = $value->slug;
}
// yonetem 3 ama sadece post getirir
$mp_events = array(
'offset' => 1,
'post_type' => 'mp-event',
'posts_per_page' => - 1,
'numberposts' => - 1,
"orderby" => "post_date",
"order" => "DESC",
"post_status" => "publish"
);
$myposts_display_doctor_department = get_posts( $mp_events );
?>
</label>
<br>
<select name="display_doctor_department" id="display_doctor_department">
<?php foreach ( $myposts_display_doctor_department as $mypost ) { ?>
<option
value="<?php echo $mypost->ID ?>" <?php echo ( CHfw_doctor_selected_get_meta( 'display_doctor_department' ) == $mypost->ID ) ? 'selected' : '' ?> ><?php echo $mypost->post_title ?></option>
<?php } ?>
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment