This repository was archived by the owner on Feb 27, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424function 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};
You can’t perform that action at this time.
0 commit comments