├── .gitignore ├── add-extra-css-class-to-the-anchor-element-in-nav-menu.md ├── add-extra-css-class-to-the-li-element-in-nav-menu.md ├── fix-no-order-found-bug-for-woocommerce.md ├── get-posts-by-category-name.md ├── get-rid-of-nagging-woocommerce-admin-notice.md └── get-single-category-name-of-a-post.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /add-extra-css-class-to-the-anchor-element-in-nav-menu.md: -------------------------------------------------------------------------------- 1 | # Add extra css class to the anchor tag in nav menu 2 | 3 | You may run into situations where the `` tag requires some extra css class in your nav menu, but the function which renders the menu leaves you disappointed because there is no default way to do that, except using a special filter. So let's do that 4 | 5 | ```php 6 | function set_anchor_class( $class = '', $location = 'primary', $append = false ) { 7 | add_filter( 'nav_menu_link_attributes', function ( $atts, $item, $args ) use ( $class, $append, $location ) { 8 | if ( !$append ) { 9 | $atts['class'] = $class; 10 | } else { 11 | $atts['class'] .= " " . $class; 12 | } 13 | return $atts; 14 | }, 10, 3 ); 15 | } 16 | ``` 17 | 18 | Instead of adding css class to every `` tag found in every `theme_location` we can also restrict it to a specific location, like this, which will work only for the `primary` theme location. 19 | 20 | ```php 21 | function set_anchor_class( $class = '', $location = 'primary', $append = false ) { 22 | add_filter( 'nav_menu_link_attributes', function ( $atts, $item, $args ) use ( $class, $append, $location ) { 23 | if ( $args->theme_location == $location ) { 24 | if ( !$append ) { 25 | $atts['class'] = $class; 26 | } else { 27 | $atts['class'] .= " " . $class; 28 | } 29 | } 30 | return $atts; 31 | }, 10, 3 ); 32 | } 33 | ``` 34 | 35 | :) Nice, eh? -------------------------------------------------------------------------------- /add-extra-css-class-to-the-li-element-in-nav-menu.md: -------------------------------------------------------------------------------- 1 | # Add extra css class to the li tag in nav menu 2 | 3 | You may run into situations where the `
  • ` tag requires some extra css class in your nav menu, but the function which renders the menu leaves you disappointed because there is no default way to do that, except using a special filter. So let's do that 4 | 5 | ```php 6 | function set_li_class( $class = '', $location = 'primary' ) { 7 | add_filter( 'nav_menu_css_class', function ( $classes, $item, $args ) use ( $class, $location ) { 8 | $classes[] = $class; 9 | return $classes; 10 | }, 10, 3 ); 11 | } 12 | ``` 13 | 14 | Instead of adding css class to every `
  • ` tag found in every `theme_location` we can also restrict it to a specific location, like this, which will work only for the `primary` theme location. 15 | 16 | ```php 17 | function set_li_class( $class = '', $location = 'primary' ) { 18 | add_filter( 'nav_menu_css_class', function ( $classes, $item, $args ) use ( $class, $location ) { 19 | if ( $args->theme_location == $location ) { 20 | $classes[] = $class; 21 | } 22 | return $classes; 23 | }, 10, 3 ); 24 | } 25 | ``` 26 | 27 | That was not tough, or was it? -------------------------------------------------------------------------------- /fix-no-order-found-bug-for-woocommerce.md: -------------------------------------------------------------------------------- 1 | # Fix no orders found bug in WooCommerces + WordPress 5x 2 | 3 | There could be many **valid** reasons for a shop owner not updating his WooCommerce to a later version. However, if he/she updates the WordPress core, he could fall into a strange situation when he will find out that no orders are displaying in his WooCommerce admin area. This is frustrating and gives a panic attack. The fix is easy though. Add the following code as a plugin, or inside the `functions.php` of your theme. 4 | 5 | ```php 6 | function fix_request_query_args_for_woocommerce( $query_args ) { 7 | if ( isset( $query_args['post_status'] ) && empty( $query_args['post_status'] ) ) { 8 | unset( $query_args['post_status'] ); 9 | } 10 | return $query_args; 11 | } 12 | add_filter( 'request', 'fix_request_query_args_for_woocommerce', 1 ); 13 | 14 | ``` 15 | 16 | And no more panic attack after that! -------------------------------------------------------------------------------- /get-posts-by-category-name.md: -------------------------------------------------------------------------------- 1 | # Find posts by category name 2 | 3 | If you need to find posts by category name, you can do that quickly using the following piece of code. 4 | 5 | ```php 6 | $post_query = new WP_Query( array( 7 | 'posts_per_page' => -1, //return all posts 8 | 'category_name' => 'your category name', 9 | ) ); 10 | 11 | echo "