create a mostly read only CPT

I did something similar recently for a simple email log (for diagnosing some problems). I don’t have time to dissect the code, but hopefully it’ll be clear enough for you. It creates a CPT for storing data that can be viewed in the admin (only), and allows the user to view and delete each post. … Read more

post_tag taxonomy with custom post type

Enabling tags in a custom post type is quite simple. You need to use ‘taxonomies’ => array(‘post_tag’) while calling register_post_type(). For Example: register_post_type(‘movies’, array( ‘labels’ => array( ‘name’ => ‘Movies’, ‘singular_name’ => ‘Movie’, ‘menu_name’ => ‘MOVIES’, ‘all_items’ => ‘All Movies’, ‘add_new’ => ‘Add A Movie’, ‘add_new_item’ => ‘Add New Movie’ ), ‘public’ => true, ‘supports’ … Read more

How to add multiple images to a custom post type single post?

Thanks for the suggestions, guys. I did some more research, and found this – https://wordpress.org/plugins/attachments/ It’s a great plugin that lets you attach images to the post without inserting them in the post and the images can be easily sorted with ajax, it’s also quite modifiable and just what I needed, and works on custom … Read more

How to List All Custom Post Types Names (Not Posts)

Get all custom post types: $post_types = get_post_types( array ( ‘_builtin’ => FALSE ), ‘objects’ ); Sort them by their name: uasort( $post_types, ‘sort_cpts_by_label’ ); /** * Sort post types by their display label. * * @param object $cpt1 * @param object $cpt2 * @return int */ function sort_cpts_by_label( $cpt1, $cpt2 ) { return strcasecmp( … Read more

expire wordpress user posts

You can set the expire date as post meta value. In single.php you can easily show that date by querying the post meta. See update_post_meta() and get_post_meta() Now, the second part of your question is pretty tricky. I can think of 2 solutions. Cron You can use wordpress cron to run at a time interval … Read more

Ordering Posts List By Taxonomy Terms?

WordPress core (as expressed by involved people on multiple occasions) strongly discourages sort by terms. It sees terms as exclusively grouping mechanism, with no ordering capabilities implied. So in your specific case WP would understand that there are different directors, that there are groups of shows done by those directors, but won’t at all understand … Read more

How to filter custom post types by custom category taxonomy

You are doing a little mistake in your $pargs As per documentation Important Note: tax_query takes an array of tax query arguments arrays (it takes an array of arrays). Also you have “post_per_page” instead of “posts_per_page” $pargs = array( ‘posts_per_page’ => ‘-1’, ‘post_type’ => ‘products’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, … Read more