Multiple level category drop-down

function parent_child_cat_select() { ?> <script type=”text/javascript”> /* <![CDATA[ */ jQuery(document).ready(function() { jQuery(‘#parent_cat’).change(function(){ var parentCat=jQuery(‘#parent_cat’).val(); // call ajax jQuery.ajax({ url:”/wp-admin/admin-ajax.php”, type:’POST’, data:’action=category_select_action&parent_cat_ID=’ + parentCat, success:function(results) { jQuery(“#sub_cat_div”).html(results); } }); }); }); /* ]]> */ </script> <form action=”<?php bloginfo(‘url’); ?>/” method=”get”> <div id=”parent_cat_div”><?php wp_dropdown_categories(“show_option_none=Select parent category&orderby=name&depth=1&hierarchical=1&id=parent_cat”); ?></div> <div id=”sub_cat_div”><select name=”sub_cat_disabled” id=”sub_cat_disabled” disabled=”disabled”><option>Select parent category first!</option></select></div> <div id=”submit_div”><input … Read more

Is there a way to have duplicate category slugs?

Short answer: No – it can’t be done. Long answer: Category slugs must be unique, regardless of parent. Although quite a few people like to call this a bug, it’s actually by design. Basically, since categories can be moved around at will, the slugs must be unique. Sure, it’s nested properly now, but if you … Read more

Redirecting specific category posts to subdomain

You can use template_redirect action hook to achieve that: add_action(‘template_redirect’, ‘redirect_category_posts’); function redirect_category_posts() { global $post; if (is_single($post->ID) && in_category(‘category-name’, $post)) { $new_url = “http://category-name.mydomain.com/{$post->post_name}.html”; wp_redirect($new_url, 301); exit; } } Please note that both posts in main domain and in sub-domain must have the same slug or post_name for this code to work.

Category count inside the link

Regular expression jiggery pokery identified: <?php $categories = wp_list_categories(‘title_li=&show_count=1&echo=0’); $categories = preg_replace(‘/<\/a> \(([0-9]+)\)/’, ‘ <span class=”count”>[\\1]</span></a>’, $categories); echo $categories; ?>

Optimal way to redirect home page to category archive?

Eliminating all of the other solutions, there is at least one remaining: template_redirect: function wpse121308_redirect_homepage() { // Check for blog posts index // NOT site front page, // which would be is_front_page() if ( is_home() ) { wp_redirect( get_category_link( $id ) ); exit(); } } add_action( ‘template_redirect’, ‘wpse121308_redirect_homepage’ ); You will need to pass the … Read more

Load categories with ajax

The error says it all, you are sending the request to a invalid host. Change this: var ajaxurl=”http://my-site.co.uk <?php bloginfo(“wpurl”);?>/wp-admin/admin-ajax.php”; To: var ajaxurl = “<?php echo esc_js( admin_url( ‘admin-ajax.php’ ) ) ?>”; Note: from your code and description I’m assuming you are generating the jQuery code within PHP and it is not in a js … Read more

Reflect nested categories in appearance > menus

Seems to be a long-standing issue. This plugin seems to do the trick. I’ve also found an alternative solution (which I’ve posted in the thread). Reproduced below: <?php add_filter( ‘nav_menu_meta_box_object’, ‘disable_pagination_in_menu_meta_box’, 9 ); function disable_pagination_in_menu_meta_box($obj) { $obj->_default_query = array( ‘posts_per_page’ => -1 ); return $obj; } ?> Update: Needs to be added with priority 9 … Read more