So I just ended up doing a query on the database for the link of the image:
wp db query “SELECT guid FROM wp_posts WHERE ID=’ID_FROM_MEDIA_IMPORT'” –silent –skip-column-names
I wrote this bash script for the whole process:
post-create.sh PATH_TO_IMAGE.FILETYPE “TITLE”
imageID=$(wp media import $1 --porcelain)
imageLINK=$(wp db query "SELECT guid FROM wp_posts WHERE ID='$imageID'" --silent --skip-column-names)
wp post create --post_title="$2" --post_status=publish --post_content="<a href=""$imageLINK""><img class=""size-full"" src=""$imageLINK"" /></a>"
Related Posts:
- Customizing individual images on posts
- Replace image attributes for lazyload plugin (data-src)
- How do I detach images from posts?
- Unattaching images from a post
- How to wrap every image in a post with a div?
- upload featured image from front end using wordpress add media button
- Retrieving and Storing Images Linked from Other Domains on Local Server?
- how to replace embedded “full” sized images within a post with the “large” ones
- Errors when uploading images in WP 3.5
- Remove Featured Image & All Media Uploaded to the Post
- How to allow multiple thumbnail upload for Posts?
- How to get all inline images in post content? [duplicate]
- Inserting Media to WordPress Posts
- Site/Post preview is not working on all social media
- unable to write to the database while uploading images
- Modified core/image rendering not showing in posts – only on pages
- Post images are not displayed in media library
- WordPress Media URLs?
- How would I attach media/images to a post based on a ID stored in a each post’s custom field
- Broken images after importing posts and opening in Gutenberg
- Optimize blog that serves hundred of images and videos
- Images being uploaded via WP Media are not attached even they are used by some CPT posts
- Adding buttons to Add New Post and Add New Page
- Custom Post Type – Category Rewrite – Remove Rewrite from Sitemap
- wp_generate_attachment_metadata is creating an empty array
- CPT archive redirects to single post
- Show posts by a custom post author
- I have a site where attachments in the wp_posts table have guid values of guid, how did this happen?
- CSS: How can I show a photo beyond the template’s column, but contained within the browser window? [closed]
- Get all attachment by post excluding featured and content inside
- Custom loop pagination links not working
- Prevent Delete Attachment by URL or When Submit
- Enable Comments Box On Custom Post Type
- How can i limit the number of posts created per category?
- Search results posts_orderby and ID
- Getting Custom Post Loop to display in Bootstrap 3 column grid
- Turn On Comments On Custom Post Types in Directory Theme
- WordPress custom Query for Posts in Category display posts multiple times
- Responsive images with custom image size
- Making a custom Pagination for multi page blog post
- ERROR: Your feed is invalid (after update WP4.7) in custom types
- Editing the default page to show all posts, rather than most recent ones
- Unable to restore from backup – how to obtain old blog posts?
- Get attachments for posts that belongs to a specific category
- List all categories with featured image from post?
- Automatically add date to the auto generation of post slug
- Removal of Media Gallery pictures
- How can you change all past posts’ images to link to none instead of the image file?
- Permission issue with custom post type – not added to menu – by plugin
- Duplicate Custom Post Type and Taxonomy Slug
- How could I change my Permalink from blog to custom structure? [closed]
- Automatically attach image to post if they have the same title
- Remove Custom Post Type Slug and add Custom Taxonomy to Permalink Structure?
- Take a received feedback item, turn it into a post
- Getting value from get_post_custom
- WP Admin register taxonomy and post type performance
- How to get the last selected media alignment setting?
- Add a custom meta box in the post options that loads some html code in the header
- Static posts page with home.php
- Calling Different Custom Post Timestamps in a table
- WordPress Multisite – Create Default Post and New Category On New Site Install
- Admin – create custom post status and display above table
- Get all images in post and comments like Twitter before post title
- custom post template file not shown, instead all the time 404.php
- Set Default Category to Username
- WordPress Automatic Filename Changer
- How to allow visitors to filter posts by multiple taxonomies
- Show only posts with images and a fixed amount of posts
- Issue where WP Featured Image will not display
- show custom post type category dropdown sorting result on same page
- Custom Post Type Rewrite To Include Parent Page(s)
- How would one change the default url structure of attachments?
- Thumbnail & Category link aside post
- Redirect to another page using contact form 7? [closed]
- If statement to check if post has image
- How to include my own css in post
- Gather posts into a cart/lightbox and share with another user
- Custom post types related to same custom post type?
- How do I insert a post with custom post type and relate it to a custom taxonomy?
- Dynamically switch template on click
- “about us”, ” contact” sections should be article(post) or page in the simple small Business website?
- Thumbnail Image to go in the post aswell
- Is it possible to customize the post according to post format in single.php?
- Customize rel=canonical tag for single blog post
- a little direction on custom post type
- disable Tab post on nav-menus page (Admin)
- What are the benefits of setting a “featured image” for a WP blog post?
- Format latest/newest post differently
- Custom taxonomy archive page problem
- Tell WP to use a specific template file in posts
- Is there a way to create a meta box that can be added multiple times to a post dynamically?
- preg_replace not removed “class”
- relating business and products with custom taxonomy?
- Best Way to Add UnEditable HTML to Posts
- update image path with words starting uppercase to lowercase chars
- How safe is it to delete old posts edits to save database space?
- Two Custom Post Types with Identical Articles Competing for the same Slug
- Custom Post Type archive
- WordPress custom post type with folder structure in slug
- Using setup_postdata() with multi-dimensional array