Let user select their own category

User taxonomies can help you achieve this, I’m working on something similar. You can install the plugin http://wordpress.org/plugins/user-taxonomies/, and register a custom taxonomy , although in my case the plugin has some limitations, may be it helps you. register_taxonomy(‘profession’, ‘user’, array( ‘public’ =>true, ‘labels’ =>array( ‘name’ =>’Professions’, ‘singular_name’ =>’Profession’, ‘menu_name’ =>’Professions’, ‘search_items’ =>’Search Professions’, ‘popular_items’ … Read more

why category__and and category__in wont work togather?

You need a query like this – $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => array( ‘car’, ‘truck’, ‘bus’ ), ‘operator’ => ‘IN’ ), array( ‘taxonomy’ => ‘category’, ‘field’ => ‘name’, ‘terms’ => ‘Toronto’ ) ) );

Add a category on all archive category pages

You need to use pre_get_posts hook. Where u can include the default category posts on other category pages. function wpse_pre_get_posts( $q ) { // its the main query, and its the category page archive if( $q->is_main_query() && $q->is_category() ) : // get the default selected category id, fallback to 1 (default one id) $default_cat = … Read more

Return category posts with WP_Query

By default WP_Query will return only the post post type. To retrieve other post types, you need to add a post_type argument. Using any will return results from all public, registered post types. $my_query = new WP_Query( array( ‘cat’ => 1, ‘post_type’ => ‘any’ ) ); var_dump($my_query->request); // debug; allows you to see the SQL … Read more

get category name in admin screen

add_action( ‘admin_menu’, ‘add_custom_submenus’, 9999 ); function add_custom_submenus() { global $submenu; if( isset($_GET[‘post’]) && get_post($_GET[‘post’]) && isset($_GET[‘action’]) && ‘edit’ == $_GET[‘action’] ) $post = get_post($_GET[‘post’]); if( isset($post) && !empty($post->post_type) && is_object_in_taxonomy($post->post_type, ‘category’) ){ foreach ( (array) get_the_category($post->ID) as $cat ) { if ( empty($cat->slug ) ) continue; $submenu[‘edit.php’][] = array( __(‘Back’), // menu title ‘edit_posts’, // … Read more

Display all sub category but one

If you’d like to exclude certain subcategories in a category archive page, try put the following code in your functions.php: function exclude_category( $query ) { if ( $query->is_category( ‘myslug’ ) && $query->is_main_query() ) { $query->set( ‘cat’, ‘-1,-1347’ ); //Add your excluded subcategories ids } } add_action( ‘pre_get_posts’, ‘exclude_category’ ); If it’s not the case, we … Read more

Problem with multiple loops in wordpress theme

The proper way to set up a secondary query, using your example code. Instead of this: $posts = get_posts(‘numberposts=1&order=DESC&orderby=post_date&category=’.get_cat_ID( ‘سیاست’ )); Do this: // Query args $custom_cat_args = array( ‘posts_per_page’ => 1, ‘order’ => ‘DESC’, ‘orderby’ => ‘post_date’, ‘cat’ => get_cat_ID( ‘سیاست’ ) ); // Instantiate query $custom_cat_query = new WP_Query( $custom_cat_args ); // Instantiate … Read more