Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit 441bbf2

Browse files
committed
rewrite tax part, not tested
1 parent 33f349e commit 441bbf2

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

command.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
function codeat_get_by_url( $args ){
2525
$url = parse_url( esc_html( $args[0] ) );
2626
$slug = $url[ 'path' ];
27-
$last_slug = array_filter( explode( '/', $slug ), 'strlen' );
28-
$last_slug = $last_slug[ count( $last_slug ) ];
27+
$split_slug = array_filter( explode( '/', $slug ), 'strlen' );
28+
$last_slug = $split_slug[ count( $split_slug ) ];
29+
$term_slug = $split_slug[ count( $split_slug ) -1 ];
2930

3031
$post = get_posts( array(
3132
'name' => $last_slug,
@@ -39,12 +40,14 @@ function codeat_get_by_url( $args ){
3940
}
4041
}
4142

42-
$taxonomies = get_taxonomies();
43-
foreach ( $taxonomies as $tax_type_key => $taxonomy ) {
44-
$tax = get_term_by( 'slug', $last_slug, $taxonomy );
45-
if( is_object( $tax ) ) {
46-
WP_CLI::log( 'term | ' . $tax->term_id . ' | ' . $tax->taxonomy );
47-
return;
43+
$taxonomies = get_taxonomies( array(), 'objects' );
44+
foreach ( $taxonomies as $taxonomy ) {
45+
if ( $taxonomy->rewrite[ 'slug' ] === $term_slug ) {
46+
$tax = get_term_by( 'slug', $last_slug, $term_slug );
47+
if( is_object( $tax ) ) {
48+
WP_CLI::log( 'term | ' . $tax->term_id . ' | ' . $tax->taxonomy );
49+
return;
50+
}
4851
}
4952
}
5053
};

0 commit comments

Comments
 (0)