How to get all children and grandchildren of a hierarchical custom post type?

You will need to loop over those posts and then do more queries for each post, repeating until you find no posts in a query. e.g. function get_posts_children($parent_id){ $children = array(); // grab the posts children $posts = get_posts( array( ‘numberposts’ => -1, ‘post_status’ => ‘publish’, ‘post_type’ => ‘microsite’, ‘post_parent’ => $parent_id, ‘suppress_filters’ => false … Read more

Put update-like notification bubble on multiple CPTs menus for pending items

I made this work iterating through a post types list, and pinpointing the correct $menu key for the post type using a secondary function (instead of manually iterating through the $menu object). Function reference: get_post_types and wp_count_posts. add_action( ‘admin_menu’, ‘pending_posts_bubble_wpse_89028’, 999 ); function pending_posts_bubble_wpse_89028() { global $menu; // Get all post types and remove Attachments … Read more

Displaying Custom Post Types In “At A Glance” Meta Box

Here is the function that I use to display CPT in the “At a glance” widget add_action( ‘dashboard_glance_items’, ‘cpad_at_glance_content_table_end’ ); function cpad_at_glance_content_table_end() { $args = array( ‘public’ => true, ‘_builtin’ => false ); $output=”object”; $operator=”and”; $post_types = get_post_types( $args, $output, $operator ); foreach ( $post_types as $post_type ) { $num_posts = wp_count_posts( $post_type->name ); $num … Read more

Only get post types based on support

I found out that get_post_types_by_support() seems to be the solution to get the desired result: $post_types = get_post_types_by_support(array(‘title’, ‘editor’, ‘thumbnail’)); The above will return post, page and any custom post type that supports title, editor and thumbnail. Since this will also return private post types, we could loop through the list and check if the … Read more

How do I append multiple taxonomies to the URL?

This is certainly possible by utilizing some rewrite rules of your own to some extent. The WP_Rewrite API exposes functions that allow you to add rewrite rules (or ‘maps’) to convert a request to a query. There are prerequisites to writing good rewrite rules, and the most important one is basic regular expression comprehension. The … Read more

How to Add Custom Taxonomy To Woocommerce Plugin

You have to do: add_action( ‘init’, ‘custom_taxonomy_Item’ ); Because: Use the init action to call this function. Calling it outside of an action can lead to troubles. see codex page register_taxonomy. Besides that : Better be safe than sorry when registering custom taxonomies for custom post types. Use register_taxonomy_for_object_type() right after the function to interconnect … Read more

How to create a custom post type without letting WordPress assign a URL

OK, so there are some arguments of register_post_type that you should use. The crucial arguments for you are: public – Controls how the type is visible to authors (show_in_nav_menus, show_ui) and readers (exclude_from_search, publicly_queryable). If it’s false, then exclude_from_search will be true, publicly_queryable – false, show_in_nav_menus – false, and show_ui – false. So the CPT … Read more