Best way to filter featured image text for a custom post type?

Regardless if you go the PHP or jQuery route, I suggest you set up your filters or enqueue your Javascript in the admin_head-post[-new].php or admin_print_scripts-post[-new].php hook. There you can be sure that the global variable $post_type is set, and can check whether it is slide. Since the post thumbnail code is called after these hooks, … Read more

Is there a way to use regular categories with custom post types?

No problem, the categories and tags are also registered as taxonomies that you can pass to the taxonomies argument when you call register_post_type(). Categories are category and tags are post_tag. You can also do this later with register_taxonomy_for_object_type(): add_action( ‘init’, ‘wpse6098_init’, 100 ); // 100 so the post type has been registered function wpse6098_init() { … Read more

Submitting posts from the front end – sanitizing data

When a post is created/edited from the admin, edit_post() is called. This function simply collects all the $_POST arguments and passes them to wp_update_post(). wp_update_post() then does some more logical checks and passes the data along to wp_insert_post(). wp_insert_post() calls sanitize_post(), which does all the heavy duty sanitization. So, yes, wp_insert_post() is the correct way … Read more

title_save_pre on post publish

The filter title_save_pre runs before the post is written to the database, and also before any of its post meta is saved to the database. So get_post_meta at this point will be blank for the first run, and always return ‘old’ data. To correct this you’ll want to hook into save_post and update the post … Read more

Hide/Show only specific categories in wp-admin new-post.php

Something like this should do it. Replace wpse_77670_getPermittedCategories() with however you select the array of permitted categories, and ‘your_custom_category’ with whatever your custom taxonomy is for your custom post type. /** * filter terms checklist args to restrict which categories a user can specify * @param array $args arguments for function get_terms() * @param array … Read more

Automatically fill custom field value on post publish/update

See add_meta_box which has a lot of demo code for working with meta fields. Here is the most relevant part for you: /* Do something with the data entered */ add_action( ‘save_post’, ‘myplugin_save_postdata’ ); /* When the post is saved, saves our custom data */ function myplugin_save_postdata( $post_id ) { // First we need to … Read more

Count posts or custom post types from last 24 hours (or from today)

You can write your own function (add it to functions.php file: function get_posts_count_from_last_24h($post_type=”post”) { global $wpdb; $numposts = $wpdb->get_var( $wpdb->prepare( “SELECT COUNT(ID) “. “FROM {$wpdb->posts} “. “WHERE “. “post_status=”publish” “. “AND post_type= %s “. “AND post_date> %s”, $post_type, date(‘Y-m-d H:i:s’, strtotime(‘-24 hours’)) ) ); return $numposts; } function get_posts_count_from_today($post_type=”post”) { global $wpdb; $numposts = $wpdb->get_var( … Read more