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

Commit 2195b3d

Browse files
committed
first commit
0 parents  commit 2195b3d

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

command.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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' );

composer.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

0 commit comments

Comments
 (0)