<?php
/*
*Plugin Name: Costom Post With Custom taxonomiy
*Author : shyam
*version : 2.0
*Author URI: https://sknetking9.blogspot.com/
*
*
*/
function crunchify_directors_custom_post_type() {
$labels = array(
'name' => __( 'Directors' ),
'singular_name' => __( 'director'),
'menu_name' => __( 'directors'),
'parent_item_colon' => __( 'Parent director'),
'all_items' => __( 'All directors'),
'view_item' => __( 'View director'),
'add_new_item' => __( 'Add New director'),
'add_new' => __( 'Add New'),
'edit_item' => __( 'Edit director'),
'update_item' => __( 'Update director'),
'search_items' => __( 'Search director'),
'not_found' => __( 'Not Found'),
'not_found_in_trash' => __( 'Not found in Trash')
);
$args = array(
'label' => __( 'directors'),
'description' => __( 'Best Crunchify directors'),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'custom-fields'),
'public' => true,
'hierarchical' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'has_archive' => true,
'can_export' => true,
'exclude_from_search' => false,
'yarpp_support' => true,
'taxonomies' => array('post_tag'),
'publicly_queryable' => true,
'capability_type' => 'page'
);
register_post_type( 'directors', $args );
}
add_action( 'init', 'crunchify_directors_custom_post_type', 0 );
add_action( 'init', 'crunchify_create_directors_custom_taxonomy', 0 );
//create a custom taxonomy name it "type" for your posts
function crunchify_create_directors_custom_taxonomy() {
$labels = array(
'name' => _x( 'Place', 'taxonomy general name' ),
'singular_name' => _x( 'Place', 'taxonomy singular name' ),
'search_items' => __( 'Search Places' ),
'all_items' => __( 'All Places' ),
'parent_item' => __( 'Parent Place' ),
'parent_item_colon' => __( 'Parent Place:' ),
'edit_item' => __( 'Edit Place' ),
'update_item' => __( 'Update Place' ),
'add_new_item' => __( 'Add New Place' ),
'new_item_name' => __( 'New Place Name' ),
'menu_name' => __( 'Place' ),
);
register_taxonomy('Places',array('directors'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'Group' ),
));
$labels = array(
'name' => _x( 'Group', 'taxonomy general name' ),
'singular_name' => _x( 'Group', 'taxonomy singular name' ),
'search_items' => __( 'Search Groups' ),
'all_items' => __( 'All Groups' ),
'parent_item' => __( 'Parent Group' ),
'parent_item_colon' => __( 'Parent Group:' ),
'edit_item' => __( 'Edit Group' ),
'update_item' => __( 'Update Group' ),
'add_new_item' => __( 'Add New Group' ),
'new_item_name' => __( 'New Group Name' ),
'menu_name' => __( 'Group' ),
);
register_taxonomy('Group',array('directors'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'Group' ),
));
}
function my_shortcode_function() {
$dir_args = array(
'post_type' => 'directors',
'order' => 'ASC',
);
$show_dir_Posts = new WP_Query($dir_args);
$title_data = '';
while ($show_dir_Posts->have_posts()) {
$show_dir_Posts->the_post();
$title_data .= the_title( '<th><button style="margin:5px;" class="btn1" name="'.get_the_id().'">','</button></th>' );
}
wp_reset_postdata();
return $title_data.'<div id="show_data"></div>';
}
add_shortcode('shortcode', 'my_shortcode_function');
// add_filter( 'the_title', function( $title ) { return $title . '<button class="btn btn-primary" id="send">click</button>'; } );
// ajax requrst handel function
function task_enqueue_scripts() {
/**
* frontend ajax requests.
*/
wp_enqueue_script( 'frontend-director-ajax', plugin_dir_url(__FILE__). 'reqajax.js', array('jquery'), null, true );
wp_localize_script( 'frontend-director-ajax', 'ajax_object',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' )
)
);
}
add_action( 'wp_enqueue_scripts', 'task_enqueue_scripts' );
// handel req of wpadmin re
add_action('wp_ajax_my_action', 'my_callback');
function my_callback() {
$id = $_POST['content'];
$my_postid = $id;//This is page id or post id
$content_post = get_post($my_postid);
$content = $content_post->post_content;
// $content = apply_filters('the_content', $content); ab dekh kya hua hai???
// $content = str_replace(']]>', ']]>', $content);
echo $content;
wp_die();
}
?>
0 Comments