WP_Query not looking at child category

You’ll have to get the child or parent categories yourself and pass all the IDs as an array via the category__in argument of WP_Query. You can use get_ancestors to get the top parent category, and get all child categories of that parent via the child_of argument of get_categories.

Rearranging posts based on categories

May be it’s a bad idea, but it’s the only. Don’t print posts immediately, but collect them in different variables: one for category “test”, one for the rest. <?php $w_h = $w_d = $last = 0; // init variables to concatenate content later $primary_posts = $secondary_posts=””; // empty array to fill later $category_names = array(); … Read more

is_category() function

My suspicion is that, for some reason, the name “51m series” or slug 51m-series is (or both are) matching is_category( 51 ). The is_category() function uses the PHP in_array() conditional to match against ID, slug, and name: if ( in_array( $cat_obj->term_id, $category ) ) return true; elseif ( in_array( $cat_obj->name, $category ) ) return true; … Read more

How to exclude uncategorized from permalink structure /%category%/%postname%/

I hope this will work for you 😀 function mf_post_link( $permalink, $post, $leavename ) { if( $post->post_type != ‘post’ ) return $permalink; // if no category, the filter is deactivated $cats = get_the_category($post->ID); if( ! count($cats) ) return $permalink; usort($cats, ‘_usort_terms_by_ID’); // order by ID $category_object = apply_filters( ‘post_link_category’, $cats[0], $cats, $post ); $category_object = … Read more

How to change the category in URL for posts in multiple categories?

Similar plugin but compatible to latest wp version 3.5.2 http://wordpress.org/plugins/wp-category-permalink/ This plugin allows you to select a ‘main’ category for your posts, for better permalinks and SEO. It uses the same meta data as the “Hikari Category Permalink” and the “sCategory Permalink”, but it has been rewritten using better and cleaner code. Requires: WP 3.5 … Read more

wp_update_nav_menu_item() to insert categories

After using the Chrome inspector on the “Appearance > Menus” categories panel I was able to sniff out the hidden form values that are passed when one manually adds a category to a custom menu via the wizard: <li> <label class=”menu-item-title”> <input type=”checkbox” class=”menu-item-checkbox” name=”menu-item[-11][menu-item-object-id]” value=”181″> Category One</label> <input type=”hidden” class=”menu-item-db-id” name=”menu-item[-11][menu-item-db-id]” value=”0″> <input type=”hidden” … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)