WordPress Custom Post Types and Taxonomies
-
i am make Custom Post Types and Taxonomies
and from admin i make in Taxonomy
good bad passthat my code of Custom Post Types and Taxonomies
<?php
function my_custom_posttypes() {
$labels = array(
‘name’ => ‘doctors’,
‘singular_name’ => ‘doctor’,
‘menu_name’ => ‘doctors’,
‘name_admin_bar’ => ‘doctor’,
‘add_new’ => ‘Add New’,
‘add_new_item’ => ‘Add New doctor’,
‘new_item’ => ‘New doctor’,
‘edit_item’ => ‘Edit doctor’,
‘view_item’ => ‘View doctor’,
‘all_items’ => ‘All doctors’,
‘search_items’ => ‘Search doctors’,
‘parent_item_colon’ => ‘Parent doctors:’,
‘not_found’ => ‘No doctors found.’,
‘not_found_in_trash’ => ‘No doctors found in Trash.’,
);$args = array(
‘labels’ => $labels,
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘menu_icon’ => ‘dashicons-id-alt’,
‘query_var’ => true,
‘rewrite’ => array( ‘slug’ => ‘doctors’ ),
‘capability_type’ => ‘post’,
‘has_archive’ => true,
‘hierarchical’ => false,
‘menu_position’ => 5,
‘supports’ => array( ‘title’, ‘editor’, ‘thumbnail’ )
);
register_post_type( ‘doctors’, $args );
}
add_action( ‘init’, ‘my_custom_posttypes’ );// Flush rewrite rules to add “review” as a permalink slug
function my_rewrite_flush() {
my_custom_posttypes();
flush_rewrite_rules();
}
register_activation_hook( __FILE__, ‘my_rewrite_flush’ );// Custom Taxonomies
function my_custom_taxonomies() {// Type of Product/Service taxonomy
$labels = array(
‘name’ => ‘Specialization’,
‘singular_name’ => ‘Specialization’,
‘search_items’ => ‘Search for Specialization’,
‘all_items’ => ‘All Types Specialization’,
‘parent_item’ => ‘Parent Type of Specialization’,
‘parent_item_colon’ => ‘Parent Type of Specialization:’,
‘edit_item’ => ‘Edit Type of Specialization’,
‘update_item’ => ‘Update Type of Specialization’,
‘add_new_item’ => ‘Add New Type of Specialization’,
‘new_item_name’ => ‘New Type of Specialization’,
‘menu_name’ => ‘Type of Specialization’,
);$args = array(
‘hierarchical’ => true,
‘labels’ => $labels,
‘show_ui’ => true,
‘show_admin_column’ => true,
‘query_var’ => true,
‘rewrite’ => array( ‘slug’ => ‘Specialization’ ),
);register_taxonomy( ‘Specialization’, array( ‘doctors’ ), $args );
}
add_action( ‘init’, ‘my_custom_taxonomies’ );
/// i want sort my post of Custom Post in page template
by all good posts then pass and at last bad////////////*/
<?php /*Template Name: doctors */?>
<?php get_header(); ?><section class=”know-your-doctor”>
<div class=”container”>
<div class=”col-md-12″>
<h1>
<?php the_title(); ?>
</h1>
<div class=”row”><?php
$args = array(
‘type’ => ‘doctors’,
‘orderby’ => ‘name’,
‘order’ => ‘ASC’,
‘taxonomy’ => ‘product-type’);
$taxonomies = get_categories( $args);
?>
<?php
$args = array(
‘post_type’ => ‘doctors’,
‘work’ => $taxonomy->slug,
‘orderby’=> ‘ID’,
‘order’=> ‘ASC’,‘posts_per_page’ => -1
);
query_posts($args) ?>
<?php
while(have_posts()) : the_post();?>
<div class=”col-md-3 col-sm-6 col-xs-6″>
<div class=”single-service”> “>
<div class=”grid”>
<figure class=”effect-apollo”>
<div class=”serv-img”> <img src=”<?php the_field(‘doc-pic’) ?>” alt=”” class=”img-responsive center”/> </div>
<h2>
<?php the_title(); ?><?php the_field(‘doc-spe’) ?>
more and booking </h2>
<figcaption> </figcaption>
</figure>
</div>
</div>
</div>
<?php endwhile; ?><!– pagination–>
<?php wp_pagenavi(); wp_reset_query(); ?>
<!– end pagination–></div>
</div>
</div>
</section>
<?php get_footer(); ?>
- The topic ‘WordPress Custom Post Types and Taxonomies’ is closed to new replies.