This repository was archived by the owner on Feb 27, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 1010 * ## OPTIONS
1111 *
1212 * <url>
13- * : Number of users to generate
1413 *
1514 * ## EXAMPLES
1615 *
1716 * wp get-by-url [your-url-with-slug]
1817 *
1918 * @accesspublic
2019 * @param array $args
21- * @param array $assoc_args
2220 * @return
2321 */
2422function codeat_get_by_url ( $ args ){
2523 $ url = esc_html ( $ args [0 ] );
2624
25+ $ hasext = pathinfo ( $ url , PATHINFO_EXTENSION );
26+ if ( !empty ( $ hasext ) ) {
27+ $ media = attachment_url_to_postid ( $ url );
28+ if ( $ media !== 0 ) {
29+ WP_CLI ::log ( 'media | ' . $ media . ' | attachment ' );
30+ return ;
31+ }
32+ }
33+
2734 $ post = url_to_post ( $ url );
2835 if ( is_object ( $ post ) ) {
2936 WP_CLI ::log ( 'post | ' . $ post ->ID . ' | ' . $ post ->post_type );
Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ Output:
2424
2525` term | 2 | post_tag `
2626
27+ Works also with attachment.
28+
2729### Why skip plugins and themes
2830
2931It is a good practice in WP CLI when you have to execute commands that are heavy of resources to not load plugins and themes for a lot of reasons.
You can’t perform that action at this time.
0 commit comments