Hi @fxfuture:
I think what you are looking for is the wp_insert_post_data
hook. You can add this code to the bottom of your theme’s functions.php
file and/or you can add it to a plugin:
add_filter('wp_insert_post_data','my_wp_insert_post_data',10,2);
function my_wp_insert_post_data($data, $postarr) {
$post_type="video";
if ($data['post_type']==$post_type && get_post($postarr['ID'])->post_status=='draft') {
global $wpdb;
$data['menu_order'] = $wpdb->get_var("SELECT MAX(menu_order)+1 AS menu_order FROM {$wpdb->posts} WHERE post_type="{$post_type}"");
}
return $data;
}
Related Posts:
- Remove Custom Taxonomy Metabox from Custom Post Type Screen
- Get terms by taxonomy AND post_type
- How can I change the admin search posts fields?
- Creating conditional blocks for WordPress Gutenberg
- Permalink Structure for Multiple Post Type Archives by Taxonomy
- Allow user to Edit Posts but not Add New?
- WordPress 4.4+ : How to revision CPT + metadata
- Removing base slug from hierarchical custom post type
- Highlight menu item when on a custom post type?
- Querying custom posts and regular posts
- Post slug changed using code doesn’t reflect on editor when post is published
- Detect meta value changes when post is updated (post_updated)
- Remove Custom Post Type menu for non-administrator users.
- Using Query Posts With Multiple Post Types And A Taxonomy
- How can I get the last posts by user role?
- Display Custom Post Type in divs just thumb and title
- Custom Taxonomy List links being re-written
- wp_list_categories and custom post types
- Post Ancestor and Child Post in Custom Post Type
- Need idea: custom post type and custom meta
- grant a privilege for roles (for example editors) and higher
- Sort posts based on multiple custom fields
- Custom Post Order for a Custom Post Type
- How to make a custom taxonomy selectable in post publish area?
- How to Separate CPT From Regular Posts?
- Specify a Page as the parent to the CPT Archive
- Remove wrong dashes from get_the_title()
- Redirect page to first post in custom post type
- Hooking in to an archive page?
- Edit / delete custom post types through web page (not admin)
- Custom columns for multiple custom post types
- post_row_actions not working for hierarchical post type
- Troubles with saving metabox
- Custom Post Type / Two level deep taxonomy (cat. and subcat.) uri problem (error 404)
- Tax query not producing any results
- How to make global post work with custom post type?
- How should I structure my post types?
- Post Quote with image on header for news site
- 301 redirect for converted post type
- Add custom post type as submenu [closed]
- Team club with CPTs and user registration + user dashboard
- Custom post type editor with dynamic selects, one drop down populating a second second drop down not working
- Custom Post Type and Category Base Rewrite Issue
- Create custom post with custom user rules
- Order a custom post type admin screen by a second custom post type title
- next_/previous_post_link() `in_same_category` appears to fail when true
- Add a ‘guide’ image to custom post type admin page
- Understanding Post Formats/Custom Post types Etc
- archive as a page, so that it can be added in the wp_menu_nav
- Displaying Custom Posts
- singular_name label in custom post type
- How to get dropdown instance value in WordPress custom Widget
- Different post title, keywords and description
- Trying to add a class to post links
- WordPress custom post categories and subcategories on category.php
- Get Terms from Custom Taxonomy and Current Post
- Catch and display error on save_post action
- custom post archive URL is wrong
- How do I call the custom Post Type name and permanent link to my php file?
- Mandatory field in Custom post
- How to store the third party script with HTML code in the wordpress custom input field?
- How to display related posts using the same taxonomy for custom types (WordPress, Pods, Woo)
- Filter custom post type admin list by custom meta column, where the column is another custom posts meta value
- Adding featured image to a new post using front-end form?
- In child theme, add CPT to custom taxonomy registered in parent theme
- How to display posts with plugin (advanced custom fields) field groups?
- Custom taxonomies not displaying in some custom posts
- Static Front Page not working for custom theme
- Is there a way to create a sidebar of bullets
- From CPT Custom Loop into Shortcode?
- Set a Default CPT taxonomy by taxonomy id
- Skip latest 3 posts from loop
- Custom taxonomy terms registered not showing when added in child theme
- How to redirect from wp-admin/edit.php to a frontend page for specific custom post type?
- How to assign post to category
- Only show categories that have posts within custom post type
- WordPress deletes custom posts instead of trash them
- Creating custom post type relationships
- Display all Custom taxonomy terms and their relevant custom posts
- wordpress query_posts with foundation 6 Accordion not working correctly
- Best way to group posts based on custom post type terms
- How to remove UI access to Custom Post Type using direct links?
- get_post_types doesn’t work in plugin
- Allow viewing the edit screen for a post type, but not make/save/publish/update changes
- Would like to add a “leaderboard” (custom field) to a custom post type
- Render custom taxonomy query as single template
- I have a custom post type that I want to query a dynamic category name from a custom meta field
- Is it possible to make one of two custom fields in Custom Post Type UI Required but not the other?
- adding a shortcode into a custom post type
- Custom Post within a custom post
- Custom My account page and custom page for editing posts
- What’s the best way to show custom post types? With page template it’s not perfect!
- show custom post types for a month
- Post count for particular term
- using a template for more then 1 page
- Add word limit in wordpress posts editor
- wordpress custom post type shows other cpt posts in admin menu
- Same slug for Custom Taxonomy archive and CPT archive – Rewrite rule not working
- is therer any wordpress function to retrieve a specific html element from post content
- WordPress post objects in one parent post object