null, 'id' => 0, 'name' => 'about', 'cat' => null, 'tag' => null ), $atts)); $link = ''; // do categories first if (!empty($cat)) { $catobj = get_category_by_slug($cat); $link = get_category_link($catobj->term_id); if (empty($content)) $content = get_cat_name($catobj->term_id); } // then tags elseif (!empty($tag)) { $tagobj = get_term_by( 'slug', $tag, 'post_tag' ); $link = get_tag_link($tagobj->term_id); if (empty($content)) $content = $tagobj->name; } // do post/page elseif (!empty($title)) { $thepost = get_page_by_title($title); if (!$thepost) { // there is no get_post_by_title, so we'll sanitize and try it as a slug global $wpdb; $id = $id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND (post_type = 'post' OR post_type = 'page') ", sanitize_title($title) )); $thepost = get_post($id); } if (empty($content)) { $thepost = get_post( $id ); // will get all post types $content = $thepost->post_title; } $link = get_permalink($id); } else { // if no ID, get post/page by name or title if (empty($id)) { global $wpdb; $id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND (post_type = 'post' OR post_type = 'page') ", $name )); } // use $content for the title if it exists; otherwise fetch page/post title if (empty($content)) { $thepost = get_post( $id ); // will get all post types $content = $thepost->post_title; } $link = get_permalink($id); } if (!empty($link)) return ''.$content.''; else return $content; // no cat, ID, or name provided; ignore this shortcode and return bare content } add_shortcode('link', 'create_anylink'); ?>