creating categories programmatically

wp_insert_category and wp_create_category are both in wp-admin/includes/taxonomy.php. They’re not general use functions and can’t be used just anywhere. wp_insert_term is, but you’re using it incorrectly. See the Codex for details on proper usage, but in short, here’s a cheat sheet: wp_insert_term( $term, $taxonomy, $args = array() ); … $defaults = array( ‘alias_of’ => ”, ‘description’ … Read more

How to use this $tax_selection variable in this custom loop?

I suppose you need to make it global. It might look like: add_action( ‘pre_get_posts’, ‘do_user_post_selection’ ); function do_user_post_selection( $query ) { if( !is_home() || !is_user_logged_in() ) return; if( isset( $query->query_vars[‘post_type’] ) && ( ‘nav_menu_item’ == $query->query_vars[‘post_type’] ) ) return; if( 1 < did_action(‘wp’) ) return; global $current_user, $tax_selection; $tax_selection = get_user_option( ‘taxonomy_selection’, $current_user->ID ); if( … Read more

Automatically show ‘taxonomy’ meta box by default in Appearance > Menus?

Thanks @guiniveretoo, perfect 🙂 Finally this is how I did (this code is used for the menu page screen options): /* Just use to find your screen_id */ add_filter(‘current_screen’, ‘the_current_screen’ ); function the_current_screen($screen) { if ( defined( ‘DOING_AJAX’ ) && DOING_AJAX ) return $screen; print_r($screen); return $screen; } /* Just use to display the options … Read more

How to display posttypes and taxonomy in standard posts, not in a separate label?

when you register a taxonomy, the second argument is the post type it is available for: register_taxonomy( $taxonomy, $object_type, $args ); if you want the taxonomy to work for a custom type as well as standard posts, you can pass an array of types: $object_type = array( ‘your_custom_type’, ‘post’ ); alternately, you can use register_taxonomy_for_object_type: … Read more

Get post-meta value of all custom-posts – lowest to highest year-count?

something like this should do the job: global $post; $years = array(); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); $this_year = get_post_meta( $post->ID, ‘event_date’, true ); if ( $this_year = date( ‘Y’, $this_year ) ) { if ( ! in_array( $this_year, $years ) ) { $years[] = $this_year; } } … Read more

Only display latest custom taxonomy post

You should save the ID of the first post in a variable (e.g $splash_post_id) and in the next loop, use “post__not_in” => $splash_post_id , in the $args array. $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => ‘1’, ‘order_by’ => ‘date’, ‘order’ => ‘DESC’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘theme’, ‘field’ => ‘slug’, ‘terms’ => … Read more