ID, $taxonomy, array( 'fields' => 'ids' ) ); # Lets only continue if we actually have post terms and if we don't have an WP_Error object. If not, return false if ( !$terms || is_wp_error( $terms ) ) return false; # Check if the users argument is valid if( is_array( $taxonomy ) && count( $taxonomy ) > 0 ){ $tax_query_arg = array(); foreach( $taxonomy as $tax ){ $tax = filter_var( $tax, FILTER_SANITIZE_STRING ); if ( taxonomy_exists( $tax ) ){ array_push( $tax_query_arg, array( 'taxonomy' => $tax, 'terms' => $terms, 'include_children' => false ) ); } } if( count( $tax_query_arg ) == 0 ){ return false; } if( count( $tax_query_arg ) > 1 ){ $tax_query_arg[ 'relation' ] = 'OR'; } }else return false; # Set the default query arguments $args = array( 'post_type' => $current_post->post_type, 'post__not_in' => array( $current_post->ID ), 'posts_per_page' => $per_page, 'tax_query' => $tax_query_arg, ); if( $get_params ){ return $args; } # Now we can query our related posts and return them $q = get_posts( $args ); return $q; } endif; /** * Adds a class 'clearfix' on post navigation markup * * @since Businex 1.0.0 * @param string $template * @param string $class * @return string */ function businex_modify_post_navigation_markup( $template, $class ){ $pos = strpos( $template,'%1$s' ); $template = substr_replace( $template, 'clearfix ', $pos, 0 ); return $template; } add_filter( 'navigation_markup_template', 'businex_modify_post_navigation_markup', 10, 2 ); if( ! function_exists( 'businex_primary_menu_fb' ) ) : /** * Fallback for primary menu. * * @since Businex 1.0.0 * @return void */ function businex_primary_menu_fb( $arg ) { if( !$arg[ 'echo' ] ){ ob_start(); } ?> get_primary_term(); $cat[0] = get_term( $wpseo_primary_term ); if ( !is_wp_error( $cat[0] ) ) { $failed = false; } } if( $failed ){ $cat = get_the_category( $id ); usort( $cat, 'businex_sort_category' ); } return $cat; } endif; if( ! function_exists( 'businex_sort_category' ) ): /** * Helper function for businex_get_the_category() * * @since Businex 1.0.0 */ function businex_sort_category( $a, $b ){ return $a->term_id < $b->term_id; } endif; if( ! function_exists( 'businex_explode_string_to_int' ) ): /** * Converts string to an array * * @since Businex 1.0.0 * @param String * @return array of integers | false */ function businex_explode_string_to_int( $str ){ if( empty( $str ) ) return false; $str = explode( ',', $str ); $arr = array(); if( count( $str ) > 0 ){ foreach( $str as $word ){ $int = absint( $word ); if( $int > 0 && ! in_array( $int, $arr ) ){ $arr[] = $int; } } } if( count( $arr ) > 0 ) return $arr; return false; } endif; if( ! function_exists( 'businex_get_menu' ) ): /** * Returns wp nav * * @since Businex 1.0.0 * @param String $location * @return String */ function businex_get_menu( $location = 'primary', $echo = true ){ $menu = null; $args = array( 'theme_location' => $location, 'fallback_cb' => false, 'echo' => $echo, 'container' => false ); switch( $location ){ case 'primary': $args[ 'fallback_cb' ] = 'businex_primary_menu_fb'; $args[ 'menu_id' ] = 'primary-menu'; $args[ 'menu_class' ] = 'primary-menu'; $menu = wp_nav_menu( apply_filters( 'businex_'.$location.'_menu', $args ) ); break; case 'topheader': $args[ 'fallback_cb' ] = 'businex_top_header_menu_fb'; $args[ 'menu_id' ] = 'top-header-menu'; $args[ 'menu_class' ] = 'top-header-menu'; $menu = wp_nav_menu( apply_filters( 'businex_'.$location.'_menu', $args ) ); break; case 'social': $args[ 'depth' ] = 1; $menu = wp_nav_menu( apply_filters( 'businex_'.$location.'_menu', $args ) ); break; default: $menu = wp_nav_menu( apply_filters( 'businex_'.$location.'_menu', $args ) ); break; } if( !$echo ){ return $menu; } } endif; if( !function_exists( 'businex_hex2rgba' ) ): /** * Convert hexdec color string to rgb(a) string * @since Businex 1.0.0 */ function businex_hex2rgba($color, $opacity = false) { $default = 'rgb(0,0,0)'; # Return default if no color provided if( empty( $color ) ) return $default; # Sanitize $color if "#" is provided if ( $color[0] == '#' ) { $color = substr( $color, 1 ); } # Check if color has 6 or 3 characters and get values if ( strlen( $color ) == 6 ) { $hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ); } elseif ( strlen( $color ) == 3 ) { $hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ); } else { return $default; } # Convert hexadec to rgb $rgb = array_map('hexdec', $hex); # Check if opacity is set(rgba or rgb) if( $opacity ){ if( abs( $opacity ) > 1 ) $opacity = 1.0; $output = 'rgba('.implode( ",",$rgb ).','.$opacity.')'; } else { $output = 'rgb('.implode( ",",$rgb ).')'; } # Return rgb(a) color string return $output; } endif;