Custom Post Types – Change order of menu items

Here is an example of one way I have managed to edits those: function wpse_custom_menu_order( $menu_ord ) { if ( !$menu_ord ) return true; return array( ‘index.php’, // Dashboard ‘separator1’, // First separator ‘edit.php’, // Posts ‘upload.php’, // Media ‘link-manager.php’, // Links ‘edit-comments.php’, // Comments ‘edit.php?post_type=page’, // Pages ‘separator2’, // Second separator ‘themes.php’, // Appearance … Read more

How do I get array of types associated with a taxonomy?

You’re using the correct code (get_taxonomy(‘dog’)->object_type) or function, but it should only be used after the taxonomy has been registered. Otherwise, the function would return a false instead of a proper taxonomy object which contains properties like object_type which is an array of post types registered for the taxonomy. And because taxonomies are normally (or … Read more

Single Template for Custom Post Type stops working after WordPress 5.4 update

Nothing changed in WP 5.4 regarding singular post types. The template hierarchy remains the same. E.g for a post type named book WP will try to load the first file it finds in this list: {selected-custom-template}.php single-book-{slug}.php single-book.php single.php singular.php index.php Your problems cause is elsewhere, if you’ve followed the standard approach to templates you … Read more

How do I order multiple custom post types in the same menu position ( menu_position = 20 – below Pages)?

There are two ways to affect where CPTs appear in the admin menu: using menu_position and controlling when the CPTs are registered. Using decimal numbers hasn’t been reliable in my experience; using an integer like 21, 22, etc. has been more effective. If you have so many CPTs there aren’t enough integers, the other trick … Read more

Access $post object when adding custom columns to list table

You don’t need a global $post object, WP gives the column callback the post ID, which is all that is needed. Looking at this question/answer, we see this code: add_filter( ‘manage_book_posts_columns’, ‘set_custom_edit_book_columns’ ); function set_custom_edit_book_columns($columns) { …. $columns[‘publisher’] = __( ‘Publisher’, ‘your_text_domain’ ); return $columns; } add_action( ‘manage_book_posts_custom_column’ , ‘custom_book_column’, 10, 2 ); function custom_book_column( … Read more

Change archive page template using pre_get_post

You corrected the filter hook name from archive-videos to template_include, but in the first function return $query; statement comes before add_filter(), so the filter is not added. add_action( ‘pre_get_posts’ ,’post_type_videos’ ); function post_type_videos( $query ) { if ( ! is_admin() && $query->is_post_type_archive( ‘videos_cpt’ ) && $query->is_main_query() ) { $query->set( ‘post_type’, ‘videos’ ); //set query arg … Read more