Update Parent post type in child theme - wordpress

I'm developing a child theme of a premium template, this comes with a custom post type with the label name of "release" but I'd like to change it to something else, I know that if I go to the functions.php file of the main theme I can change it easily but I'd like to change it from my child theme?
here is the code
<?php
add_action('init', 'kentha_release_register_type');
if(!function_exists('kentha_release_register_type')){
function kentha_release_register_type() {
$labelsrelease = array(
'name' => esc_html__("Release",'kentha'),
'singular_name' => esc_html__("Release",'kentha'),
'add_new' => esc_html__("Add new",'kentha'),
'add_new_item' => esc_html__("Add new release",'kentha'),
'edit_item' => esc_html__("Edit release",'kentha'),
'new_item' => esc_html__("New release",'kentha'),
'all_items' => esc_html__("All releases",'kentha'),
'view_item' => esc_html__("View release",'kentha'),
'search_items' => esc_html__("Search release",'kentha'),
'not_found' => esc_html__("No releases found",'kentha'),
'not_found_in_trash' => esc_html__("No releases found in trash",'kentha'),
'menu_name' => esc_html__("Album releases",'kentha')
);
$args = array(
'labels' => $labelsrelease,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'page',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 40,
'page-attributes' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'show_in_menu' => true,
'menu_icon' => 'dashicons-controls-play',
'supports' => array('title', 'thumbnail','editor', 'page-attributes' )
);
if (function_exists('ttg_custom_post_type')){
ttg_custom_post_type( "release" , $args );
}
/* ============= create custom taxonomy for the releases ==========================*/
$labels = array(
'name' => __( 'Release genres','kentha' ),
'singular_name' => esc_html__( 'Genre','kentha' ),
'search_items' => esc_html__( 'Search by genre','kentha' ),
'popular_items' => esc_html__( 'Popular genres','kentha' ),
'all_items' => esc_html__( 'All releases','kentha' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => esc_html__( 'Edit genre','kentha' ),
'update_item' => esc_html__( 'Update genre','kentha' ),
'add_new_item' => esc_html__( 'Add New genre','kentha' ),
'new_item_name' => esc_html__( 'New genre Name','kentha' ),
'separate_items_with_commas' => esc_html__( 'Separate genres with commas','kentha' ),
'add_or_remove_items' => esc_html__( 'Add or remove genres','kentha' ),
'choose_from_most_used' => esc_html__( 'Choose from the most used genres','kentha' ),
'menu_name' => esc_html__( 'Music genres','kentha' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'genre' ),
);
if(function_exists('ttg_custom_taxonomy')){
ttg_custom_taxonomy('genre','release',$args );
}
$fields = array(
array( // Repeatable & Sortable Text inputs
'label' => esc_html__( 'Release Tracks','kentha' ), // <label>
'desc' => esc_html__( 'Add one for each track in the release','kentha' ), // description
'id' => 'track_repeatable', // field id and name
'type' => 'repeatable', // type of field
'sanitizer' => array( // array of sanitizers with matching kets to next array
'featured' => 'meta_box_santitize_boolean',
'title' => 'sanitize_text_field',
'desc' => 'wp_kses_data'
),
'repeatable_fields' => array ( // array of fields to be repeated
'releasetrack_mp3_demo' => array(
'label' => esc_html__( 'MP3 Demo','kentha' ),
'desc' => esc_html__( '(Never upload your full quality tracks, someone can steal them)','kentha' ), // description
'id' => 'releasetrack_mp3_demo',
'type' => 'file'
),
'releasetrack_track_title' => array(
'label' => esc_html__( 'Title','kentha' ),
'id' => 'releasetrack_track_title',
'type' => 'text'
),
'releasetrack_artist_name' => array(
'label' => esc_html__( 'Artists','kentha' ),
'desc' => esc_html__( '(All artists separated bu comma)','kentha' ), // description
'id' => 'releasetrack_artist_name',
'type' => 'text'
),
'releasetrack_buy_url' => array(
'label' => esc_html__( 'Track Buy link','kentha' ),
'desc' => esc_html__( 'A link to buy the single track','kentha' ), // description
'id' => 'releasetrack_buyurl',
'type' => 'text'
),
'icon_type' => array(
'label' => esc_html__( 'Track icon (cart icon is default)','kentha' ),
'id' => 'icon_type',
'type' => 'select',
'default' => 'cart',
'options' => array(
array('label' => 'cart','value' => 'cart'),
array('label' => 'download','value' => 'download')
)
),
)
)
);
$fields_links = array(
array( // Repeatable & Sortable Text inputs
'label' => esc_html__( 'Custom Buy Links','kentha' ), // <label>
'desc' => esc_html__( 'Add one for each link to external websites','kentha' ), // description
'id' => 'track_repeatablebuylinks', // field id and name
'type' => 'repeatable', // type of field
'sanitizer' => array( // array of sanitizers with matching kets to next array
'featured' => 'meta_box_santitize_boolean',
'title' => 'sanitize_text_field',
'desc' => 'wp_kses_data'
),
'repeatable_fields' => array ( // array of fields to be repeated
'custom_buylink_anchor' => array(
'label' => esc_html__( 'Custom Buy Text','kentha' ),
'desc' => esc_html__( '(example: Itunes, Beatport, Trackitdown)','kentha' ),
'id' => 'cbuylink_anchor',
'type' => 'text'
),
'custom_buylink_url' => array(
'label' => esc_html__('Custom Buy URL','kentha' ),
'desc' => esc_html__( '(example: http://...)','kentha' ), // description
'id' => 'cbuylink_url',
'type' => 'text'
)
)
)
);
$fields_release = array(
array(
'label' => esc_html__('Main artist', "kentha"),
'id' => 'releasetrack_artist',
'type' => 'post_chosen',
'posttype' => 'artist'
),
array(
'label' => esc_html__( 'Label','kentha' ),
'id' => 'general_release_details_label',
'type' => 'text'
),
array(
'label' =>esc_html__( 'Release date (YYYY-MM-DD)','kentha' ) ,
'id' => 'general_release_details_release_date',
'type' => 'date'
),
array(
'label' => esc_html__( 'Catalog Number','kentha' ),
'id' => 'general_release_details_catalognumber',
'type' => 'text'
)
);
$details_box = new custom_add_meta_box( 'release_details', 'Release Details', $fields_release, 'release', true );
$sample_box = new custom_add_meta_box( 'release_tracks', 'Release Tracks', $fields, 'release', true );
$buylinks_box = new custom_add_meta_box( 'release_buylinkss', 'Custom Buy Links', $fields_links, 'release', true );
}}
I need to update in Child Teme the icon_type options adding this extra fields
array('label' => 'spotify','value' => 'spotify')
Any suggestion?
Thanks in advance

Related

wordpress - query custom post type by category slug

I'm trying to query a custom post type by its category slug, but its not working at all, it always return blank - like no results
my custom post type definitions:
add_action( 'init', 'custom_post_albuns' );
// The custom function to register a movie post type
function custom_post_albuns() {
// Set the labels, this variable is used in the $args array
$labels = array(
'name' => __( 'Albuns' ),
'singular_name' => __( 'Album' ),
'add_new' => __( 'Add New Album' ),
'add_new_item' => __( 'Add New Album' ),
'edit_item' => __( 'Edit Album' ),
'new_item' => __( 'New Album' ),
'all_items' => __( 'All Albuns' ),
'view_item' => __( 'View Album' ),
'search_items' => __( 'Search Albuns' ),
'featured_image' => 'Featured Image',
'set_featured_image' => 'Add Featured Image'
);
// The arguments for our post type, to be entered as parameter 2 of register_post_type()
$args = array(
'labels' => $labels,
'description' => 'm6 Records Albuns',
'public' => true,
'menu_position' => 6,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments', 'custom-fields' ),
'has_archive' => true,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'has_archive' => true,
'menu_icon' => 'dashicons-album',
'query_var' => 'album'
);
// Call the actual WordPress function
// Parameter 1 is a name for the post type
// Parameter 2 is the $args array
register_post_type( 'album', $args);
}
add_action( 'init', 'create_album_taxonomies', 0 );
function create_album_taxonomies() {
$labels = array(
'name' => _x( 'Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Categories' ),
'all_items' => __( 'All Categories' ),
'parent_item' => __( 'Parent Category' ),
'parent_item_colon' => __( 'Parent Category:' ),
'edit_item' => __( 'Edit Category' ),
'update_item' => __( 'Update Category' ),
'add_new_item' => __( 'Add New Category' ),
'new_item_name' => __( 'New Category Name' ),
'menu_name' => __( 'Categories' ),
);
$args = array(
'hierarchical' => true, // Set this to 'false' for non-hierarchical taxonomy (like tags)
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'albuns' ),
);
register_taxonomy( 'albuns_categories', array( 'album' ), $args );
}
and my query:
$argsPost = array(
'post_type'=>'album',
'orderby'=>'date',
'order' => 'DESC',
'posts_per_page'=>'4',
'tax_query' => array(
array(
'taxonomy' => 'albuns_categories',
'field' => 'slug',
'terms' => array( 'ANYTERM' )
)
)
);
and I can't bring a list of albuns (if I remove the tax_query part, it returns to me all the "albuns" custom post type).
Do someone have any ideias???
Thanks!!
You can try
$argsPost = array(
'post_type'=>'album',
'orderby'=>'date',
'order' => 'DESC',
'posts_per_page'=>'4',
'tax_query' => array(
array(
'taxonomy' => 'albuns_categories',
'field' => 'slug',
'terms' => array( 'ANYTERM' ),
'operator' => 'IN'
)
)
);

WP Bakery - Displaying taxonomy in grid

I have a taxonomy which I have created as follows:
function understrap_custom_taxonomies() {
$post_types_index = array('cs_publications', 'cs_projects');
$taxs = array(
'cs_themes' => array(
'menu_title' => 'Themes',
'plural' => 'Themes',
'singular' => 'Theme',
'hierarchical' => true,
'slug' => 'theme',
'post_type' => array( 'post', 'cs_publications', 'cs_projects', 'cs_events')
)
);
foreach( $taxs as $tax => $args ) {
$labels = array(
'name' => _x( $args['plural'], 'taxonomy general name' ),
'singular_name' => _x( $args['singular'], 'taxonomy singular name' ),
'search_items' => __( 'Search '.$args['plural'] ),
'all_items' => __( 'All '.$args['plural'] ),
'parent_item' => __( 'Parent '.$args['plural'] ),
'parent_item_colon' => __( 'Parent '.$args['singular'].':' ),
'edit_item' => __( 'Edit '.$args['singular'] ),
'update_item' => __( 'Update '.$args['singular'] ),
'add_new_item' => __( 'Add New '.$args['singular'] ),
'new_item_name' => __( 'New '.$args['singular'].' Name' ),
'menu_name' => __( $args['menu_title'] )
);
$tax_args = array(
'hierarchical' => $args['hierarchical'],
'labels' => $labels,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'show_in_rest' => true,
'with_front' => false,
'rewrite' => array( 'slug' => $args['slug'] ),
);
register_taxonomy( $tax, $args['post_type'], $tax_args );
}
}
add_action('init', 'understrap_custom_taxonomies');
I am now trying to get the value for "cs_themes" to display in a WP Bakery grid using the custom field element:
However no matter whether I type "cs_themes", "taxonomy_cs_themes" or any other logical combination, it doesn't seem to pull through the values. Any advice would be much appreciated.

SSL breaks a users ability to upload an image

I have a problem that is driving me crazy. I'm working on a business listing website in WordPress which allows business users to upload their businesses, along with a description and an image.
All was working fine in development but as soon as a SSL is installed on the site, image uploads produce an error:
An error occurred in the upload. Please try again later.
The inspector console shows:
400 error: Failed to load resource: the server responded with a status of 400 (Bad Request)
and the file cannot be uploaded.
I'm out of my depth here - any ideas please?
I think this is the relevant part of the theme library - not sure it it helps?
<?php
if ( ! search_and_go_elated_listing_plugin_installed() ) {
//exit if listing plugin is not installed
return;
}
if(!function_exists('search_and_go_elated_map_listing_type_settings')) {
function search_and_go_elated_map_listing_type_settings() {
$meta_box_listing_type = search_and_go_elated_create_meta_box(array(
'scope' => 'listing-type-item',
'title' => 'Listing Type Settings',
'name' => 'listing_type_settings_meta_box'
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_phone',
'type' => 'yesno',
'label' => esc_html__( 'Show Phone Field', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_website',
'type' => 'yesno',
'label' => esc_html__( 'Show Website Field', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_email',
'type' => 'yesno',
'label' => esc_html__( 'Show Email Field', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_gallery',
'type' => 'yesno',
'label' => esc_html__( 'Show Gallery Images', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_video',
'type' => 'yesno',
'label' => esc_html__( 'Show Video', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_audio',
'type' => 'yesno',
'label' => esc_html__( 'Show Audio', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_work_hours',
'type' => 'yesno',
'label' => esc_html__( 'Show Working Hours', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_social_icons',
'type' => 'yesno',
'label' => esc_html__( 'Show Social Icons', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_price',
'type' => 'yesno',
'label' => esc_html__( 'Show Price', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_sidebar_gallery',
'type' => 'yesno',
'label' => esc_html__( 'Show Sidebar Gallery', 'search-and-go' ),
'description' => '',
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
search_and_go_elated_create_meta_box_field(array(
'name' => 'eltd_listing_type_show_booking_form',
'type' => 'yesno',
'label' => esc_html__( 'Show Booking Form', 'search-and-go' ),
'description' => esc_html__( 'Requires Elated Booking Plugin to be installed', 'search-and-go' ),
'default_value' => 'yes',
'parent' => $meta_box_listing_type
));
//init icon pack hide and show array. It will be populated dinamically from collections array
$listing_type_icon_pack_hide_array = array();
$listing_type_icon_pack_show_array = array();
//do we have some collection added in collections array?
if (is_array(search_and_go_elated_icon_collections()->iconCollections) && count(search_and_go_elated_icon_collections()->iconCollections)) {
//get collections params array. It will contain values of 'param' property for each collection
$listing_type_icon_collections_params = search_and_go_elated_icon_collections()->getIconCollectionsParams();
//foreach collection generate hide and show array
foreach (search_and_go_elated_icon_collections()->iconCollections as $dep_collection_key => $dep_collection_object) {
$listing_type_icon_pack_hide_array[$dep_collection_key] = '';
//we need to include only current collection in show string as it is the only one that needs to show
$listing_type_icon_pack_show_array[$dep_collection_key] = '#eltd_listing_type_icon_' . $dep_collection_object->param . '_container';
//for all collections param generate hide string
foreach ($listing_type_icon_collections_params as $listing_icon_collections_param) {
//we don't need to include current one, because it needs to be shown, not hidden
if ($listing_icon_collections_param !== $dep_collection_object->param) {
$listing_type_icon_pack_hide_array[$dep_collection_key] .= '#eltd_listing_type_icon_' . $listing_icon_collections_param . '_container,';
}
}
//remove remaining ',' character
$listing_type_icon_pack_hide_array[$dep_collection_key] = rtrim($listing_type_icon_pack_hide_array[$dep_collection_key], ',');
}
}
search_and_go_elated_create_meta_box_field(
array(
'parent' => $meta_box_listing_type,
'type' => 'select',
'name' => 'listing_type_icon_pack',
'default_value' => 'font_awesome',
'label' => esc_html__( 'Listing Type Icon Pack', 'search-and-go' ),
'description' => esc_html__( 'Choose icon pack for listing', 'search-and-go' ),
'options' => search_and_go_elated_icon_collections()->getIconCollections(),
'args' => array(
'dependence' => true,
'hide' => $listing_type_icon_pack_hide_array,
'show' => $listing_type_icon_pack_show_array
)
)
);
if (is_array(search_and_go_elated_icon_collections()->iconCollections) && count(search_and_go_elated_icon_collections()->iconCollections)) {
//foreach icon collection we need to generate separate container that will have dependency set
//it will have one field inside with icons dropdown
foreach (search_and_go_elated_icon_collections()->iconCollections as $collection_key => $collection_object) {
$icons_array = $collection_object->getIconsArray();
//get icon collection keys (keys from collections array, e.g 'font_awesome', 'font_elegant' etc.)
$icon_collections_keys = search_and_go_elated_icon_collections()->getIconCollectionsKeys();
//unset current one, because it doesn't have to be included in dependency that hides icon container
unset($icon_collections_keys[array_search($collection_key, $icon_collections_keys)]);
$listing_icon_hide_values = $icon_collections_keys;
$listing_icon_container = search_and_go_elated_add_admin_container(
array(
'parent' => $meta_box_listing_type,
'name' => 'listing_type_icon_' . $collection_object->param . '_container',
'hidden_property' => 'listing_type_icon_pack',
'hidden_value' => '',
'hidden_values' => $listing_icon_hide_values
)
);
search_and_go_elated_create_meta_box_field(
array(
'parent' => $listing_icon_container,
'type' => 'select',
'name' => 'listing_type_icon_' . $collection_object->param,
'default_value' => '',
'label' => esc_html__( 'Listing Type Icon', 'search-and-go' ),
'description' => esc_html__( 'Choose Listing Type Icon', 'search-and-go' ),
'options' => $icons_array,
)
);
}
}
search_and_go_elated_add_custom_fields_creator(array(
'name' => 'listing_custom_fields' ,
'label' => esc_html__( 'Custom Fields Creator', 'search-and-go' ),
'desciption' => esc_html__( 'Create listing type custom fields', 'search-and-go' ),
'parent' => $meta_box_listing_type
));
$feature_list_title = search_and_go_elated_add_admin_section_title(
array(
'parent' => $meta_box_listing_type,
'title' => esc_html__( 'Listing Type Feature List', 'search-and-go' ),
'name' => 'listing_type_feature_list_title'
)
);
search_and_go_elated_add_repeater_field(array(
'name' => 'eltd_listing_type_repeater',
'parent' => $meta_box_listing_type,
'fields' => array(
array(
'type' => 'textsimple',
'name' => 'eltd_listing_type_feature_list',
'label' => '',
'description' => '',
),
)
)
);
}
add_action('search_and_go_elated_meta_boxes_map', 'search_and_go_elated_map_listing_type_settings');
}

How to filter custom posts with same taxonomy term as the current post?

I am trying to filter the custom posts with my custom taxonomy called "events". The code I have should check the "events" taxonomy's name for the current post and then only list the posts within the same group.
I have checked the codex page https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters but was unable to get this to work. Does anyone have any advice?
$post_terms = wp_get_object_terms($post->ID, 'events');
$post_term = $post_terms[0]->name;
$args = array(
'post_type' => 'events',
'post_status' => 'publish',
'posts_per_page' => -1,
'post__not_in' => array(124470, 124455),
'tax_query' => array(
array(
'taxonomy' => 'events',
'field' => 'name',
'terms' => $post_term,
),
),
);
update, added code below as requested.
/* custom taxonomies */
function my_custom_events_taxonomies(){
register_taxonomy(
'events',
'events',
array(
'label' => 'Events type',
'rewrite' => array( 'slug' => 'Events'),
'hierarchical' => false,
'custom-fields' => true,
)
);
}
add_action ( 'init', 'my_custom_events_taxonomies');
custom post type below:
function events_post_type() {
$labels = array(
'name' => _x( 'Events', 'Post Type General Name', 'remco' ),
'singular_name' => _x( 'Events', 'Post Type Singular Name', 'remco' ),
'menu_name' => __( 'Events', 'remco' ),
'name_admin_bar' => __( 'Events', 'remco' ),
'archives' => __( 'Events Archives', 'remco' ),
'parent_item_colon' => __( 'Parent Events:', 'remco' ),
'all_items' => __( 'All Events', 'remco' ),
'add_new_item' => __( 'Add New Events', 'remco' ),
'add_new' => __( 'Add New', 'remco' ),
'new_item' => __( 'New Item', 'remco' ),
'edit_item' => __( 'Edit Item', 'remco' ),
'update_item' => __( 'Update Item', 'remco' ),
'view_item' => __( 'View Item', 'remco' ),
'search_items' => __( 'Search Item', 'remco' ),
'not_found' => __( 'Not found', 'remco' ),
'not_found_in_trash' => __( 'Not found in Trash', 'remco' ),
'insert_into_item' => __( 'Insert into item', 'remco' ),
'uploaded_to_this_item' => __( 'Uploaded to this item', 'remco' ),
'items_list' => __( 'Items list', 'remco' ),
'items_list_navigation' => __( 'Items list navigation', 'remco' ),
'filter_items_list' => __( 'Filter items list', 'remco' ),
);
$args = array(
'label' => __( 'Events', 'remco' ),
'description' => __( 'Events', 'remco' ),
'labels' => $labels,
'supports' => array( 'title', 'editor','revisions', 'thumbnail', 'custom-fields' ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 9,
'menu_icon' => 'dashicons-calendar' ,
'show_in_admin_bar' => true,
'show_in_nav_menus' => false,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'taxonomies' => 'events'
);
register_post_type( 'Events', $args );
}
add_action( 'init', 'events_post_type', 0 );
The standard way to get posts from custom post type with custom texonomies is
$args = array('post_type' => 'custom_post_type',
'tax_query' => array(
array(
'taxonomy' => 'custom_taxonomy',
'field' => 'slug',
'terms' => $custom_term->slug,
),
),
);
$loop = new WP_Query($args);

How to create custom post types in WordPress?

I want to know the procedure of how to create custom post types with WordPress. I will be thankful if anyone help me with complete procedure of code and plugins. I will also be writing a blog post regarding this issue and I need help from top contributors of Stackoverflow.
Add code similar to this to your functions.php
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'your_custom_name',
array(
'labels' => array(
'name' => __( 'Custom_names' ),
'singular_name' => __( 'Custom_names' )
),
'public' => true,
'has_archive' => true,
)
);
}
after it you can see a another option in your dashbooard left bar to add custom post.
see more about Post Types
<?php
require_once 'wp-load.php'; //path of wp-load.php
$name = 'my post';
$content = 'dummy Content here';
$featured_image = 'fullimage url.jpg'; //pass here full image url
$post_data = array(
'post_title' => wp_strip_all_tags( $name ),
'post_content' => $content,
'post_status' => 'publish',
'post_type' => 'post',
'post_author' => 1,
'post_category' => array(1,2),
'page_template' => ''
);
$post_id = wp_insert_post( $post_data, $error_obj );
// for custom field
//add_post_meta( $post_id, 'post_date', 'Dec 5, 2018' ); // second parameter is your custom field name, 3rd parameter is value
generate_Featured_Image($featured_image, $post_id );
function generate_Featured_Image( $image_url, $post_id ){
$upload_dir = wp_upload_dir();
$image_data = file_get_contents($image_url);
$filename = basename($image_url);
if(wp_mkdir_p($upload_dir['path']))
$file = $upload_dir['path'] . '/' . $filename;
else
$file = $upload_dir['basedir'] . '/' . $filename;
file_put_contents($file, $image_data);
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name($filename),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $file, $post_id );
require_once(ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
$res1= wp_update_attachment_metadata( $attach_id, $attach_data );
$res2= set_post_thumbnail( $post_id, $attach_id );
echo 'post created...';
}
?>
function my_custom_event() {
$labels = array(
'name' => _x( 'Events', 'post type general name' ),
'singular_name' => _x( 'Events', 'post type singular name' ),
'add_new' => _x( 'Add New', 'Events' ),
'add_new_item' => __( 'Add New Events' ),
'edit_item' => __( 'Edit Events' ),
'new_item' => __( 'New Events' ),
'all_items' => __( 'All Events' ),
'view_item' => __( 'View Events' ),
'search_items' => __( 'Search Events' ),
'not_found' => __( 'No Events found' ),
'not_found_in_trash' => __( 'No Events found in the Trash' ),
'parent_item_colon' => '',
'menu_name' => 'Events'
);
$args = array(
'labels' => $labels,
'description' => 'Events',
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'menu_position' => 5,
'supports' => array( 'title' , 'thumbnail', 'editor', 'page-attributes'),
'has_archive' => true,
);
register_post_type( 'event', $args );
}
add_action( 'init', 'my_custom_event' );
## This is my full working code for creating custom post types ##
function slide_init()
{
$labels = array(
'name' => 'Slider',
'singular_name' => 'Slider',
'menu_name' => 'Slider',
'name_admin_bar' => 'Slider',
'add_new' => 'Add New Slider',
'add_new_item' => 'Add New Slider',
'new_item' => 'New Slider',
'edit_item' => 'Edit Slider',
'view_item' => 'View Slider',
'all_items' => 'All Slider Images',
'search items' => 'Search Slider',
'parent_item_colon' => 'Parent Slider',
'not_found' => 'No Slider Found',
'not_found_in_trash' => 'No Slider Found In Trash',
);
$args = array(
'labels' => $labels,
'public' => true,
'publicaly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'Slider' ),
'capability_type' => 'post',
'has_archive' => true,
'Hierarchical' => false,
'menu_position' => null,
'menu_icon' => 'dashicons-format-image',
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments','hierarchical','trackbacks','custom-fields','revisions','page-attributes'),
'taxonomies' =>array('category'),
);
register_post_type('Slider',$args);
register_taxonomy('Slider_category','Slider',array('hierarchical' => true, 'label' => 'Category', 'query_var' => true, 'rewrite' => array('slug' => 'slider-category')));
}
add_action('init','slide_init');
/** Meet the team custom post
You can use below WordPress script to create custom post type without any plugins */
$labels = array(
'name' => _x('Team', 'Team', 'Team') ,
'singular_name' => _x('Team', 'Team', 'rjis') ,
'menu_name' => _x('Meet the Team', 'admin menu', 'rjis') ,
'name_admin_bar' => _x('Team', 'add new on admin bar', 'rjis') ,
'add_new' => _x('Add New', 'Team', 'rjis') ,
'add_new_item' => __('Add New Team', 'rjis') ,
'new_item' => __('New Team', 'rjis') ,
'edit_item' => __('Edit Team', 'rjis') ,
'view_item' => __('View Team', 'rjis') ,
'all_items' => __('All Team Members', 'rjis') ,
'search_items' => __('Search Team', 'rjis') ,
'parent_item_colon' => __('Parent Team:', 'rjis') ,
'not_found' => __('No Team found.', 'rjis') ,
'not_found_in_trash' => __('No Team found in Trash.', 'rjis')
);
$args = array(
'labels' => $labels,
'description' => __('Description.', 'Meet the team') ,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array(
'slug' => 'team'
) ,
'capability_type' => 'post',
'has_archive' => false,
'hierarchical' => false,
'menu_position' => null,
'supports' => array(
'title',
'editor',
'author',
'thumbnail',
'excerpt'
) ,
'menu_icon' => PLUGIN_URL . "images/team.png"
);
register_post_type('team', $args);
Here Career word is Used for Given name for the PostType. You can make multiple post type just change Carrer Name.
// career CUSTOM POST
$labels = array(
'name' => 'career',
'singular_name' => 'career',
'add_new' => 'Add career',
'add_new_item' => 'Add New career',
'edit_item' => 'Edit career',
'new_item' => 'New career',
'all_items' => 'All career',
'view_item' => 'View career',
'search_items' => 'Search career',
'not_found' => 'No career found',
'not_found_in_trash' => 'No career found in Trash',
'parent_item_colon' => '',
'menu_name' => 'career'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'taxonomies' => array('career_cat'),
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail',
'custom-fields'
)
);
register_post_type('career', $args);
$labels = array(
'name' => 'career_Category',
'singular_name' => 'career',
'search_items' => 'Search career_Categories',
'all_items' => 'All career_Categories',
'parent_item' => 'Parent career_Category',
'parent_item_colon' => 'Parent career_Category:',
'edit_item' => 'Edit career_Category',
'update_item' => 'Update career_Category',
'add_new_item' => 'Add New career_Category',
'new_item_name' => 'New Category Name',
'menu_name' => 'career_Categories'
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'rewrite' => false,
'capabilities' => array('manage_terms')
);
register_taxonomy('career_cat', array('career'), $args);
add_theme_support('post-thumbnails', array('career'));
set_post_thumbnail_size(100, 100);
"Portfolio" name Used for the PostType. You can Add portfolio-category remove and also add tags.
function ag_custom_post_type_init() {
$ag_cust_post_argu = '';
$ag_cust_post_argu = array(
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'query_var' => true,
'has_archive' => true,
'hierarchical' => true,
'menu_position' => null,
'menu_icon' => null,
'supports' => array( 'title', 'editor' )
);
register_post_type(
'portfolio', array(
'labels' => array('name' => __( 'Portfolio' ), 'singular_name' => __( 'portfolio' ) ),
'hierarchical' => true,
'public' => true,
'rewrite' => array(
'slug' => 'portfolio',
'with_front' => false,
),
'menu_icon' => 'dashicons-admin-site',
'has_archive' => true,
'parent' => 'Portfolio',
'supports' => array('page-attributes','title', 'editor', 'thumbnail', 'comments', 'excerpt'),
$ag_cust_post_argu,
)
);
}
add_action( 'init', 'ag_custom_post_type_init' );
function custom_post_type_tax_init_portfolio() {
register_taxonomy(
'portfolio-category',
'portfolio',
array(
'label' => __( 'Categories' ),
'hierarchical' => true,
'rewrite' => array(
'slug' => 'portfolio-category',
'with_front' => false,
),
)
);
}
add_action( 'init', 'custom_post_type_tax_init_portfolio' );
function custom_post_type_tag_init_portfolio() {
register_taxonomy('portfolio_tag', 'portfolio', array(
'hierarchical' => false,
'label' => "Tags",
'singular_name' => "tag",
'rewrite' => array(
'slug' => 'portfolio-tag',
'with_front' => false,
),
'query_var' => true
)
);
}
add_action( 'init', 'custom_post_type_tag_init_portfolio' );

Resources