Adding categories to all blogs at once

You could write a script for that, here is something I wrote in Perl lately: first the sql statements to check if the term already exist and if not insert it: the prepared statements: my $wts = $dbh->prepare( “SELECT term_id FROM $tb_wp_terms WHERE name = ?”) or die “Couldn’t prepare statement: ” . dbh->errstr; my … Read more

How to get Total Post In a Selceted category

I have one solution for you. This code will show and unordered list with the name of the category and the count of posts containded in it. <ul class=”myClass”> <?php $categories = get_categories(‘number=100’); foreach ($categories as $cat) { echo “<li>”. $cat->cat_name . ” Total posts: “. $cat->category_count .”</li>”; } ?> </ul> Retrieves the 100 first … Read more

How to block a category from one user and enable the category for the rest of the users

We will use the my_force_login() function that will force the users to login when they press on a specific category. Wp-login.php if ( ( empty( $redirect_to ) || $redirect_to == ‘wp-admin After this condition ends write this part if ($user_name == “student”) { wp_safe_redirect(“http://www.domain.co.il /?cat=4”); } else { wp_safe_redirect($redirect_to); } Inside the condition write the … Read more

WordPress Ordering Problem. How to fix ordering 1-10-100 issue?

Based on the research I’ve done on this, using term meta data is a better all around approach to ordering terms. However, I was able come up with this snippet which does sort the terms by their name, numerically: add_filter( ‘terms_clauses’, ‘wpse247680_terms_clauses’, 10, 3 ); function wpse247680_terms_clauses( $pieces, $taxonomies, $args ) { // Bail if … Read more

How do I set a specific template for sub-categories?

I would recommend using the category_template filter – just check if the current category is an ancestor of 67: function wpse_179617_category_template( $template ) { if ( cat_is_ancestor_of( 67, get_queried_object_id() /* The current category ID */ ) ) $template = locate_template( ‘category-slider.php’ ); return $template; } add_filter( ‘category_template’, ‘wpse_179617_category_template’ );

How to add style to category link?

You can use the_category filter to hook a callback function like this: add_filter(‘the_category’,’add_class_to_category’,10,3); function add_class_to_category( $thelist, $separator, $parents){ $class_to_add = ‘my-category-class’; return str_replace(‘<a href=”‘, ‘<a class=”‘ . $class_to_add . ‘” href=”‘, $thelist); }

How to display child categories of current category’s parent category?

I now realize there’s an easier way to do this: <?php if (is_category( )) { $thiscat = get_category( get_query_var( ‘cat’ ) ); $catid = $thiscat->cat_ID; $parent = $thiscat->category_parent; if (!empty ($parent) ) { //child category pages $catlist = get_categories( array( ‘child_of’ => $parent, ‘orderby’ => ‘id’, ‘order’ => ‘DESC’, ‘exclude’ => $catid, ‘hide_empty’ => ‘0’ … Read more

Name of last category level for a post

Try the following. I’ve used get_the_terms so it is readily extendible to any taxonomy. This will return an array of terms (event if it contains just one). For instance, the post may have terms a,b,c,d,e in the relationship: a > b > c (parent > child) d > e In which case the following will … Read more