Please help me. I'm new to WordPress and creating a custom posts. Export WordPress Custom post type Data CSV, XML, and pdf from the Front-end button.
Please help me. I'm new to WordPress and creating a custom posts. Export WordPress Custom post type Data CSV, XML, and pdf from the Front-end button.
here is my current code:-
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type('servicelist',
array(
'labels' => array(
'name' => __( 'Service-Details' ),
'singular_name' => __( 'Service - Detail' ),
'add_new' => 'Add Service',
'all_items' => 'All Service'
),
'description' => __( 'Service Details' ),
'public' => true,
'hierarchical' => true,
'has_archive' => true,
'supports' => array(
'title',
'thumbnail',
'custom-fields',
'page-attributes'
),
'show_in_menu' => true,
'menu_icon' => 'dashicons-visibility',
'menu_position' => 20
));
register_taxonomy('division', 'servicelist',
array(
'hierarchical' => false,
'label' => __('Division'),
'query_var' => 'division',
'rewrite' => array('slug' => 'division' )
));
register_taxonomy('district', 'servicelist',
array(
'hierarchical' => false,
'label' => __('District'),
'query_var' => 'district',
'rewrite' => array('slug' => 'district' )
));
register_taxonomy('upazila', 'servicelist',
array(
'hierarchical' => false,
'label' => __('Upazila'),
'query_var' => 'upazila',
'rewrite' => array('slug' => 'upazila' )
));
register_taxonomy('service-type', 'servicelist',
array(
'hierarchical' => false,
'label' => __('Service type'),
'query_var' => 'service-type',
'rewrite' => array('slug' => 'service-type' )
));
}
<span id="ex" class="ng-binding">Export</span>
Related
I have made my own theme. There in function.php i create a custom post-type called Agenda with the slug "schulung":
function ABECrm_post_type() {
$labels = array(
'name' => __( 'Agenden', 'ABECrm' ),
'singular_name' => __( 'Agenda', 'ABECrm' ),
'add_new' => __( 'Neue Agenda', 'ABECrm' )
);
$args = array(
'label' => __( 'agenda', 'ABECrm' ),
'description' => __( 'Hier werden die Agenda-Seiten eingetragen', 'ABECrm' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'custom-fields', 'page-attributes' ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 20,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
'show_in_rest' => true,
'rewrite' => array('slug' => 'schulung'),
'menu_icon' => 'dashicons-admin-page',
'taxonomies' => array( 'post_tag' ),
);
register_post_type( 'agenden', $args );
So first i had the slug "Schulung" - then as mistake "Schulung'" - at the end "schulung".
It seems that there are build redircts now - and the crawler still sees the directory "Schulung" and "Schulung'". At "Schulung" there are "Agendas" made - in "Schulung'" not.
My targets now:
how to delete the information of "Schulung'" and the redirects?
how to delete the directory "Schulung" but not the redirects...
I'm trying to get custom post types, but I can not seem to find any solution. The WP REST API documentation only returns blog posts.
Note: I'm using the Dooplay theme
The code below is in the file tipo.php
directory: inc > includes > series
if( ! function_exists( 'doo_series' ) ) {
function doo_series() {
$labels = array(
'name' => _x('TV Shows', 'Post Type General Name','mtms'),
'singular_name' => _x('TV Show', 'Post Type Singular Name','mtms'),
'menu_name' => __d('TV Shows %%PENDING_COUNT_TV%%'),
'name_admin_bar' => __d('TV Shows'),
'all_items' => __d('TV Shows'),
);
$rewrite = array(
'slug' => get_option('dt_tvshows_slug','tvshows'),
'with_front' => true,
'pages' => true,
'feeds' => true,
);
$args = array(
'label' => __d('TV Show'),
'description' => __d('TV series manage'),
'labels' => $labels,
'supports' => array('title', 'editor','comments','thumbnail','author'),
'taxonomies' => array('genres'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-welcome-view-site',
'show_in_admin_bar' => true,
'show_in_nav_menus' => false,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'capability_type' => 'post',
);
register_post_type('tvshows', $args );
}
add_action('init', 'doo_series', 0 );
get_template_part('inc/includes/series/metabox');
}
Compare with
register_post_type( 'post', array(
'labels' => array(
'name_admin_bar' => _x( 'Post', 'add new from admin bar' ),
),
'public' => true,
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
'_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
'capability_type' => 'post',
'map_meta_cap' => true,
'menu_position' => 5,
'hierarchical' => false,
'rewrite' => false,
'query_var' => false,
'delete_with_user' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
'show_in_rest' => true,
'rest_base' => 'posts',
'rest_controller_class' => 'WP_REST_Posts_Controller',
) );
which registers the built in post type post. Observe the last three fields. These fields must be set to make the post type accessible via REST.
ADDENDUM
Actually only 'show_in_rest' is required as WordPress has default values for the other two. Also, if a developer wrote his own WP_REST_Controller for the custom post type instead of using the builtin WP_REST_Posts_Controller then even this is not required as his own WP_REST_Controller can call the register_rest_route() functions by some other means.
I have a Custom Post Type like
function cpt_Projects() {
$labels = array(
'name' => 'Projects',
'singular_name' => 'Project',
'menu_name' => 'Projects',
'name_admin_bar' => 'Projects',
'parent_item_colon' => 'Parent Projects:',
'all_items' => 'All Projects',
'view_item' => 'View Project',
'add_new_item' => 'Add New Project',
'add_new' => 'Add New Project',
'new_item' => 'New Projects',
'edit_item' => 'Edit Project Item',
'update_item' => 'Update Project Item',
'search_items' => 'Search Project Item',
'not_found' => 'Project Not found',
'not_found_in_trash' => 'Project Not found in Trash',
);
$args = array(
'label' => 'ProjectsCPT',
'description' => 'This Post Type Adds Eyeglasses to Website',
'labels' => $labels,
'supports' => array( 'title', 'thumbnail', 'editor'),
'taxonomies' => array( 'ProjectsTax' ),
'register_meta_box_cb' => 'add_details_metabox',
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
);
register_post_type( 'ProjectsCPT', $args );
}
add_action( 'init', 'cpt_Projects', 0 );
and a Metabox like
function add_details_metabox($post_type) {
$types = array('post', 'page', 'ProjectsCPT');
if (in_array($post_type, $types)) {
add_meta_box(
'details-metabox',
'Project Details',
'detail_meta_callback',
$post_type,
'normal',
'high'
);
}
}
after running the code the Metabox is showing on all Pages and Posts but not on Custom Post Type ProjectsCPT Can you please let me know what I am doing wrong? (It works fine if I remove the if statement
if (in_array($post_type, $types)) {}
but this add metabox to all Posts and Pages which is not what I need to do
Can you please add 'rewrite' => array('slug' => 'ProjectsCPT'), in your register_post_type $args
below example here:
$args = array(
'label' => 'ProjectsCPT',
'description' => 'This Post Type Adds Eyeglasses to Website',
'labels' => $labels,
'supports' => array( 'title', 'thumbnail', 'editor'),
'taxonomies' => array( 'ProjectsTax' ),
'register_meta_box_cb' => 'add_details_metabox',
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => array('slug' => 'ProjectsCPT'),
'capability_type' => 'post',
);
Add metabox like
function add_details_metabox($post_type) {
$types = array('post', 'page', 'ProjectsCPT');
if (in_array($post_type, $types)) {
add_meta_box(
'details-metabox',
'Project Details',
'detail_meta_callback',
$types,
'normal',
'high'
);
}
}
Seen a bunch or responses that talk about post ID, and menus... but this is a brand new blog. I am building a plugin, but when I register a custom post type I get this error...
Catchable fatal error: Object of class WP_Post could not be converted to string in /wp-includes/formatting.php on line 1280
register_post_type('car_post', array(
'labels' => array(
'name' => 'Car Content'
),
'singular_label' => 'Car Content',
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'show_in_menu' => 'car-post',
'rewrite' => array("slug" => "car_post"),
'supports' => array( 'title', 'editor', 'author', 'revisions', 'comments' )
)
);
Anyone have an idea on what could possibly be causing that? If I comment out the custom post block... then no errors are thrown.
Custom post types are registered this way.
<?php
add_action( 'init', 'my_post_type' );
function my_post_type() {
register_post_type('car_post', array(
'labels' => array(
'name' => 'Car Content'
),
'singular_label' => 'Car Content',
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'show_in_menu' => 'car-post',
'rewrite' => array("slug" => "car_post"),
'supports' => array( 'title', 'editor', 'author', 'revisions', 'comments' )
)
);
}
?>
I have created new post type in my theme but when i try to get to the permalink for the post, it give me that the post not found
function my_post_type_news() {
register_post_type( 'news',
array(
'label' => __('News'),
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'menu_position' => 5,
'rewrite' => array(
'slug' => 'news',
'with_front' => FALSE,
),
'supports' => array(
'title',
'thumbnail',
'editor',
'excerpt')
)
);
register_taxonomy('news_category', 'news', array('hierarchical' => true, 'label' => 'News Categories', 'singular_name' => 'Category', "rewrite" => true, "query_var" => true));
}
add_action('init', 'my_post_type_news');
function my_post_type_news() {
register_post_type( 'news',
array(
'label' => __('News'),
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'menu_position' => 5,
'rewrite' =>false,
'supports' => array(
'title',
'thumbnail',
'editor',
'excerpt')
)
);
register_taxonomy('news_category', 'news', array('hierarchical' => true, 'label' => 'News Categories', 'singular_name' => 'Category', "rewrite" => true, "query_var" => true));
}
add_action('init', 'my_post_type_news');
Use above function, it will works. I have changed rewrite as false.
Hope it helps.