Shortcode category using slug in addition to name and id?
-
Hi Mat,
It seems like the shortcode category attribute takes the category name, but doesn’t take the slug. I’m looking at lines 127 through 136 in SimpleLinksFactory.php:
foreach( $this->query_args[ 'category' ] as $cat ){ if( is_numeric( $cat ) ){ $cat = get_term_by( 'id', $cat, 'simple_link_category' ); } else { $cat = get_term_by( 'name', $cat, 'simple_link_category' ); } if( ! empty( $cat->term_id ) ){ $all_cats[] = $cat->term_id; } }
Would it be possible to modify this to search for slug as well? I just find slugs much easier to deal with. Since get_term_by returns false if the term can’t be found, maybe it could look something like this?
$cat = get_term_by( 'name', $cat, 'simple_link_category' ); if (!$cat) { $cat = get_term_by( 'slug', $cat, 'simple_link_category' ); }
Let me know what you think.
Thanks!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Shortcode category using slug in addition to name and id?’ is closed to new replies.