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 2121 * @param array $assoc_args
2222 * @return
2323 */
24- function codeat_get_by_url (){
25- if ( empty ( $ url ) ){
26- WP_CLI ::error ("An environment variable must be set for DEPLOY_URL. " );
27- }
28-
29- $ url = parse_url ( $ url );
30- $ slug = ['path ' ];
31- $ post = get_page_by_path ( $ slug );
24+ function codeat_get_by_url ( $ args ){
25+ $ url = parse_url ( esc_html ( $ args [0 ] ) );
26+ $ slug = $ url ['path ' ];
27+ $ last_slug = array_filter ( explode ('/ ' , $ slug ), 'strlen ' );
28+ $ last_slug = $ last_slug [count ($ last_slug )];
29+ $ post = get_posts (array (
30+ 'name ' => $ last_slug ,
31+ 'posts_per_page ' => 1 ,
32+ ));
33+ $ post = $ post [ 0 ];
3234 if ( is_object ( $ post ) ) {
3335 WP_CLI ::log ( $ post ->ID . ' | ' . $ post ->post_type );
3436 return ;
3537 }
3638
37- $ tax = get_term_by ( 'slug ' , $ slug );
38- if ( is_object ( $ tax ) ) {
39- WP_CLI ::log ( $ tax ->term_id . ' | ' . $ post ->taxonomy );
40- return ;
39+ $ taxonomies = get_taxonomies ();
40+ foreach ( $ taxonomies as $ tax_type_key => $ taxonomy ) {
41+ $ tax = get_term_by ( 'slug ' , $ last_slug , $ taxonomy );
42+ if ( is_object ( $ tax ) ) {
43+ WP_CLI ::log ( $ tax ->term_id . ' | ' . $ tax ->taxonomy );
44+ return ;
45+ }
4146 }
42-
43- WP_CLI ::log ( '' );
4447};
4548
4649WP_CLI ::add_command ( 'get-by-url ' , 'codeat_get_by_url ' );
You can’t perform that action at this time.
0 commit comments