How to Remove Certain Screen Options and Table Columns from post type in wp_list_table?

What you need is to modify the $columns variable that is used during list display which you can modify using the ‘manage_posts_columns’ and ‘manage_pages_columns’ hooks for post_type=”post” and post_type=”page”, respectively. If you want to ignore custom post types you can inspect the 2nd parameter passed to ‘manage_posts_columns’ as I did in my example to show … Read more

Can I have Post Types under other Post Types in Admin menu?

Yes, this capability is available with register_post_type, via the show_in_menu argument, but whether or not the particular plugin you are using supports this I don’t know. add_action( ‘init’, ‘wpa70679_custom_types’ ); function wpa70679_custom_types() { register_post_type( ‘parent_type’, array( ‘public’ => true, ‘labels’ => array( ‘name’ => ‘Parent post type’ ) ) ); register_post_type( ‘child_type’, array( ‘public’ => … Read more

Only list categories that contain posts of a specific custom post type

Put the following in your functions.php: function wp_list_categories_for_post_type($post_type, $args=””) { $exclude = array(); // Check ALL categories for posts of given post type foreach (get_categories() as $category) { $posts = get_posts(array(‘post_type’ => $post_type, ‘category’ => $category->cat_ID)); // If no posts found, … if (empty($posts)) // …add category to exclude list $exclude[] = $category->cat_ID; } // … Read more

Loading custom page template via plugin

To add custom template in page attributes template section you have to first add your template to dropdown and load it in template_include hook when current page has selected it as current template. /** * Add “Custom” template to page attirbute template section. */ function wpse_288589_add_template_to_select( $post_templates, $wp_theme, $post, $post_type ) { // Add custom … Read more

How to add relationships between custom post types?

Ideally, you’d want to cast your vote into adding the infamous post2post relationship, which is still missing: http://core.trac.wordpress.org/ticket/14513 In the meanwhile, the workarounds are three: Map your posts to specially crafted taxonomies. (slow) Store relationships in postmeta. (very slow if you ever need to use that in a join statement) Create your own post2post table.

Creating relationships between multiple content types [closed]

Why not do… $my_post_types = array( ‘post’, ‘page’, ‘topic’, ‘case’, ‘note’, ‘question’, ‘therapy_guideline’ ); p2p_register_connection_type( array( ‘name’ => ‘my_post_relationships’, ‘from’ => $my_post_types, ‘to’ => $my_post_types, ‘sortable’ => ‘any’, ‘reciprocal’ => false, ‘cardinality’ => ‘many-to-many’, ‘title’ => array( ‘from’ => ‘Children’, ‘to’ => ‘Parent’, ), ‘admin_column’ => ‘any’, ) ); Or something similar? Edit: A way … Read more

Filtering a WP_Query meta_query by numeric values isn’t working

Try an array of arrays in your meta query. $args = Array( ‘post_type’ => ‘event’, ‘posts_per_page’ => -1, ‘meta_key’ => ‘event_date’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( ‘key’ => ‘event_date’, ‘compare’ => ‘>=’, ‘value’ => intval(strtotime(date(‘Y-m-d’))), ‘type’ => ‘numeric’ ) ), ); $query = new WP_Query( $args );