rewrite get parameter with custom post type

I think it should work. First you need to register your rewrite rule and the parameter: function my_init() { add_rewrite_rule( ‘gallery/(.+?)/?$’, ‘index.php?post_type=gallery&param=$matches[1]’, ‘top’ ); add_rewrite_tag(‘%param%’,'([^&]+)’); } add_action(‘init’, ‘my_init’); Then you can read the parameter value from the query: $param = get_query_var(‘param’); Don’t forget to flush the rewrites. (just view the rewrite settings page to flush … Read more

Custom post status and preview

So actually everything were more simpler, as long as someone (namely me) would have looked how “draft” post status works. Apparently there are a lot of variables that wordpress codex does not reveal / has documented, such as the following: register_post_status(‘purchased’, array( /* ‘label’ => _x( ‘Purchased’, ‘post’ ), ‘public’ => false, ‘exclude_from_search’ => true, … Read more

Add content before/after admin post wp-list-table

This has probably been solved many times here on this site, but maybe not with all your requirements? So let me try to answer it here: You can try to use the all_admin_notices and in_admin_footer actions, wrapped inside the load-edit.php action to target the edit.php page: add_action( ‘load-edit.php’, function(){ $screen = get_current_screen(); // Only edit … Read more

Restrict a Post Types Post Status

I wonder if you could use something as simple as this: (similar to the suggestion of @ialocin) /** * Use the “Force” on the post status 😉 */ add_action( ‘wp_insert_post_data’, function( $data, $postarr ){ $change_post_status = array( ‘draft’, ‘private’ ); // Edit to your needs if( ‘cpt’ === $data[‘post_type’] && in_array( $data[‘post_status’], $change_post_status, TRUE ) … Read more