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 1+ <?php
2+
3+ if ( ! class_exists ( 'WP_CLI ' ) ) {
4+ return ;
5+ }
6+
7+ /**
8+ * Get the id with post type or taxonomy by URL.
9+ *
10+ * ## OPTIONS
11+ *
12+ * <url>
13+ * : Number of users to generate
14+ *
15+ * ## EXAMPLES
16+ *
17+ * wp get-by-url [your-url-with-slug]
18+ *
19+ * @accesspublic
20+ * @param array $args
21+ * @param array $assoc_args
22+ * @return
23+ */
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 );
32+ if ( is_object ( $ post ) ) {
33+ WP_CLI ::log ( $ post ->ID . ' | ' . $ post ->post_type );
34+ return ;
35+ }
36+
37+ $ tax = get_term_by ( 'slug ' , $ slug );
38+ if ( is_object ( $ tax ) ) {
39+ WP_CLI ::log ( $ tax ->term_id . ' | ' . $ post ->taxonomy );
40+ return ;
41+ }
42+
43+ WP_CLI ::log ( '' );
44+ };
45+
46+ WP_CLI ::add_command ( 'get-by-url ' , 'codeat_get_by_url ' );
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " codeatcode/get-by-url" ,
3+ "description" : " Get the id and post type or taxonomy by the url" ,
4+ "type" : " wp-cli-package" ,
5+ "homepage" : " https://github.com/codeatcode" ,
6+ "authors" : [],
7+ "minimum-stability" : " dev" ,
8+ "autoload" : {
9+ "files" : [ " command.php" ]
10+ },
11+ "require" : {
12+ "wp-cli/wp-cli" : " >=2.0.0" ,
13+ "php" :" >=5.4"
14+ }
15+ }
You can’t perform that action at this time.
0 commit comments