Make custom column sortable

Make sure to change MY_POST_TYPE, MY_CUSTOM_COLUMN and MY_META_KEY to the actual values. First, add your custom column. Unset the date and set it again to keep it in the last column. You can skip this step. <?php function my_manage_MY_POST_TYPE_columns( $columns ) { // save date to the variable $date = $columns[‘date’]; // unset the ‘date’ … Read more

Replacing the title in admin list table

1. Change post title in post list column I misunderstood what you wanted – obviously. You can do that like this: add_action( ‘admin_head-edit.php’, ‘wpse152971_edit_post_change_title_in_list’ ); function wpse152971_edit_post_change_title_in_list() { add_filter( ‘the_title’, ‘wpse152971_construct_new_title’, 100, 2 ); } function wpse152971_construct_new_title( $title, $id ) { //print_r( $title ); //print_r( $id ); return ‘new’; } Making use of the admin_head-$hook_suffix … Read more

Change Custom Post Type slug

The register_post_type_args filter can be used to modify post type arguments: add_filter( ‘register_post_type_args’, ‘wpse247328_register_post_type_args’, 10, 2 ); function wpse247328_register_post_type_args( $args, $post_type ) { if ( ‘portfolio’ === $post_type ) { $args[‘rewrite’][‘slug’] = ‘stories’; } return $args; }

Get the first post term

I’m not sure what you mean by ‘first’ taxonomy… but, $terms = get_the_terms( $post->ID, ‘mytaxonomy’ ); returns an array of taxonomy term objects, so $term = array_pop($terms); Would give you the first term in the array. And then: echo ‘<a href=”‘.get_term_link($term->slug, ‘mytaxonomy’).'”>’.$term->name.'</a>,’ (You may want to include some if statements, in case an empty array … Read more

Shouldn’t this be easy?! Custom post type/custom taxonomy permalink

Follow the advice on this question as you did already, but add this to your code: add_action( ‘generate_rewrite_rules’, ‘fix_literature_category_pagination’ ); function fix_literature_category_pagination( $wp_rewrite ) { unset($wp_rewrite->rules[‘literature/([^/]+)/page/?([0-9]{1,})/?$’]); $wp_rewrite->rules = array( ‘literature/?$’ => $wp_rewrite->index . ‘?post_type=literature’, ‘literature/page/?([0-9]{1,})/?$’ => $wp_rewrite->index . ‘?post_type=literature&paged=’ . $wp_rewrite->preg_index( 1 ), ‘literature/([^/]+)/page/?([0-9]{1,})/?$’ => $wp_rewrite->index . ‘?literature_category=’ . $wp_rewrite->preg_index( 1 ) . ‘&paged=’ . … Read more

How to change permalink structure for custom post type and it’s taxonomies?

Ok I think I might have a solution. I have no idea if this is the right way to accomplish this, but as for now it’s the only thing that seems to work. add_filter(‘rewrite_rules_array’, ‘mmp_rewrite_rules’); function mmp_rewrite_rules($rules) { $newRules = array(); $newRules[‘portfolio/(.+)/(.+?).html$’] = ‘index.php?project=$matches[2]’; $newRules[‘portfolio/(.+)/?$’] = ‘index.php?project_category=$matches[1]’; return array_merge($newRules, $rules); } add_filter(‘request’, ‘mmp_rewrite_request’); function mmp_rewrite_request($vars) … Read more

How to disable generation of default image sizes for some custom post types?

I think the only solution you have at the moment is to disable all intermediate image sizes: add_filter( ‘intermediate_image_sizes’, ‘__return_empty_array’, 99 ); And then manually generate them, depending on the post type, by hooking into ‘wp_generate_attachment_metadata’, where you do have access to the attachment id (and therefore to it’s parent post): function do_your_stuff( $data, $attachment_id … Read more