-
Notifications
You must be signed in to change notification settings - Fork 93
Description
Feature Request
It'd be convenient to be able to wp post get foo instead of having to manually look up the ID and then run wp post get 32425.
Is your feature request directly related to a specific, existing command?
The user interacts with post get in the entities repo, but it seems like it'd be implemented in Fetchers\Post in this repo.
- Yes, I reviewed the contribution guidelines.
Describe your use case and the problem you are facing
I often know a URL like https://example.org/my-cpt/foo/, and want to run something like wp post get 32523 to get some info about the post. In order to do that, I have to:
- Switch to a browser
- Login to
wp-admin - Visit the URL
- Click
Editin the admin toolbar - Copy the ID out of the URL
- Switch back to terminal
- Paste the ID
If feels like that could be simplified.
Describe the solution you'd like
Fetchers\User, term get, etc already allow passing slugs in addition to IDs. It'd be much more convenient if I just could type wp post get my-cpt/foo. Maybe something like:
if ( is_numeric( $identifier ) ) {
$post = get_post( $identifier );
} else {
$cpt_slug = 'my_cpt'; // get by extracting first part of path and mapping to a rewrite rule?
$post = get_page_by_path( 'foo', OBJECT, $cpt_slug );
}There'd need to be extra logic to handle other URL patterns like archives etc, but there may be a way to leverage parse_request() or something to do most of that work for us.
Alternatively, maybe I could pass a full --URL, and then leave ID empty, like:
wp post get --url=https://example.org/my-cpt/foo
...and the bootstrap process would populate the global $post based on that?