Automatically sorting custom post type admin area by a custom field

Rather save the event meta field date(s) as a unix-timestamp, instead of a string, or you’ll be making life too difficult for yourself. It just makes date comparisons so much easier. Here’s an example of how to convert your YYYY/MM/DD format to a unix timestamp: $date=”2010/09/22″; $dateParts = explode(“https://wordpress.stackexchange.com/”, trim($date)); if (count($dateParts) == 3) { … Read more

WP insert post and custom taxonomy

Where is the code that catches an processes the $_POST data? Is it in a template file? Or is it in a function that is run on a hook? If it’s the latter, and if taxonomy_exists() is returning false as you suggest here (http://wordpress.stackexchange.com/questions/45798/wp-insert-post-and-custom-taxonomy#comment58402_45810), it’s possible that you’re checking before register_taxonomy has had a chance … Read more

Hide View and preview from custom post types

You need to set argument public to false at register_post_type() function. Whether a post type is intended to be used publicly either via the admin interface or by front-end users. Default: false ‘false’ – Post type is not intended to be used publicly and should generally be unavailable in wp-admin and on the front end … Read more

Mandatory excerpt for custom post type

The code adds a filter to wp_insert_post_data: add_filter(‘wp_insert_post_data’, ‘mandatory_excerpt’); And here’s the callback: function mandatory_excerpt($data) { $excerpt = $data[‘post_excerpt’]; if (empty($excerpt)) { if ($data[‘post_status’] === ‘publish’) { add_filter(‘redirect_post_location’, ‘excerpt_error_message_redirect’, ’99’); } $data[‘post_status’] = ‘draft’; } return $data; } The filter callback is passed $data, which as per the Codex includes the following post data: ‘post_author’, … Read more

List all posts commented by current user

If we want to avoid any filters and manual SQL queries, we could try (untested): $args = array( ‘post_type’ => ‘foods’, ‘posts_per_page’ => 5, ‘post__in’ => array_unique( wp_list_pluck( get_comments( array( ‘user_id’ => get_current_user_id() ) ), ‘comment_post_ID’ ) ), ); $my_query = new WP_Query( $args );