Taxonomy Templates

According to the Codex: taxonomy-{taxonomy}.php – If the taxonomy were sometax, WordPress would look for taxonomy-sometax.php What I do when using custom taxonomy/custom post types is exactly what you mentioned in the second sentence. Make a page template and a page in the back end. Choose the template you built as the template to use … Read more

WordPress tax_input only if logged in

You can use wp_set_object_terms after the post is saved and in case it fails you will get reason for that ex: $new_lead = array( ‘post_title’ => $lead_name, ‘post_content’ => $lead_message, ‘post_type’ => ‘leads’, ‘post_status’ => ‘publish’, ); $lid = wp_insert_post($new_lead); $status = wp_set_object_terms($lid,$term_id,’lead-status’); Now this does the save but $status will hold the reason for … Read more

Show the author’s count of total amount of posts assign to a custom taxonomy term

/** * Get the author post count for a tax query. * * @link http://wordpress.stackexchange.com/q/159160/1685 * * @param array $tax_query * @return int */ function wpse_159160_get_author_posts_by_tax( $tax_query ) { global $wpdb; $where = get_posts_by_author_sql( ‘post’, true, get_post()->post_author ); $tax_query = new WP_Tax_Query( $tax_query ); $sql = $tax_query->get_sql( $wpdb->posts, ‘ID’ ); return ( int ) $wpdb->get_var( … Read more

Query to change custom post type with specific category

I would do it in php in two parts rather than one big raw sql statement, for safety reasons, eg in your “functions.php” put: function wpse160706() { $old_post_type=”films”; $new_post_type=”post”; $category_slug = ‘directors’; $taxonomy = ‘category’; global $wpdb; $sql = $wpdb->prepare( ‘SELECT p.ID FROM ‘ . $wpdb->posts . ‘ AS p’ . ‘ JOIN ‘ . … Read more