Custom Post type & Taxonomy URL structure

After forever, I figured out an answer! First: we register the custom post type & custom taxonomy: add_action( ‘init’, ‘register_sps_products_post_type’ ); function register_sps_products_post_type() { register_post_type( ‘sps-product’, array( ‘labels’ => array( ‘name’ => ‘Products’, ‘menu_name’ => ‘Product Manager’, ‘singular_name’ => ‘Product’, ‘all_items’ => ‘All Products’ ), ‘public’ => true, ‘publicly_queryable’ => true, ‘show_ui’ => true, ‘show_in_menu’ … Read more

Restrict Contributors to view only their own custom post types?

You need to use the action hook pre_get_posts. See the comments for details and modify the Custom Post Type(s) to your own: add_action( ‘pre_get_posts’, ‘filter_cpt_listing_by_author_wpse_89233’ ); function filter_cpt_listing_by_author_wpse_89233( $wp_query_obj ) { // Front end, do nothing if( !is_admin() ) return; global $current_user, $pagenow; wp_get_current_user(); // http://php.net/manual/en/function.is-a.php if( !is_a( $current_user, ‘WP_User’) ) return; // Not the … Read more

Reducing the use of global $post

When I need to deal with $post variable on admin, I usually use a class to early catch and wrap global $post variable, obtaining an universal way to access to it, without repetitely relying on the global variable. class MyAdminPost { private static $post; public static function init() { $p_get = filter_input(INPUT_GET, ‘post’, FILTER_SANITIZE_NUMBER_INT); $p_post … Read more

How to get custom post type label and singular label from its slug?

get_post_type_object() will return, as the name suggests, an object that contains the post type information. You may want to var_dump() it to inspect it contents. You’ll see that it includes (among other stuff) another object, labels that contains all the registered labels for the specific post type. $pt = get_post_type_object( ‘books’ ); // These two … Read more

Fail to compare dates in meta_query

I have exact the same problem here, except i use the std. post type (post) and a category in my query. everything works except the sort order. $d = date(“Y-m-d”); $args = array( ‘post_type’ => ‘post’, ‘category_name’ => ‘events’, ‘post_status’ => ‘publish,draft,pending,future,private’, // just for me ‘meta_key’ => ‘event_start’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, … Read more