Using WP_Query, I want to show posts that are associated with a custom taxonomy term

Your tax query should be an array of arrays. Important Note: tax_query takes an array of tax query arguments arrays (it takes an array of arrays). This construct allows you to query multiple taxonomies by using the relation parameter in the first (outer) array to describe the boolean relationship between the taxonomy arrays. https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters ‘tax_query’ … Read more

How can I lock specific posts (cpt’s) from editing by anyone other than ADMINS

Use the map_meta_cap filter to conditionally prevent users who cannot manage_options (i.e. administrators) from editing/deleting certain posts: function wpse_188368_map_meta_cap( $caps, $cap, $user_ID, $args ) { if ( in_array( $cap, array( ‘delete_post’, ‘edit_post’ ) ) && $args && ! current_user_can( ‘manage_options’ ) /** Only proceed for non-administrators */ ) { $post_id = $args[0]; if ( in_array( … Read more

Showing a meta box in a custom post type on a page

If you are not using multiple key & values, I’d try it this way // This function adds a meta box with a callback function of my_metabox_callback() function add_my_meta_box() { $var1 = ‘this’; $var2 = ‘that’; add_meta_box( ‘metabox_id’, ‘Metabox Title’, ‘my_metabox_callback’, ‘page’, ‘normal’, ‘low’, array( ‘foo’ => $var1, ‘bar’ => $var2) ); } // $post … Read more

CPT structure questions

Legacy reasons. At the beginning WP only had posts. No. There are uncountable other things connected. You can query for it separately, have other permissions, different backend UI and much more. Finding the right template might be one thing, but then again it doesn’t have to be as the template hierarchy can be modified in … Read more

Show post count number assigned to custom taxonomy

Normally usage of get_term() or get_term_by() is pretty much clear cut. See the basic example below: // ID is needed $term_by_id = get_term( 12345, ‘destination’ ); echo $term_by_id->count; // Or if you e.g. want use the name (or slug or id or term_taxonomy_id) $term_by_name = get_term_by( ‘name’, ‘greece’, ‘destination’ ); echo $term_by_name->count; Note: I said … Read more

Create custom WP_List_Table in post_type

You can use the pre_get_posts filter to modify requested posts, this filter works in the admin area too, so you don’t need to go to the trouble of creating a new post list table class First lets add a query var to the URL of your ‘My Cases’ page: function register_adminMenu(){ add_submenu_page(‘edit.php?post_type=case&mycases=mine’, ‘My Cases’, ‘My … Read more